3 # This chunk of stuff was generated by App::FatPacker. To find the original
4 # file's code, look for the end of this BEGIN block or the string 'FATPACK'
8 $fatpacked{"MetaCPAN/API/Tiny.pm"} = <<'METACPAN_API_TINY';
9 package MetaCPAN::API::Tiny;
11 $MetaCPAN::API::Tiny::VERSION = '1.131730';
15 # ABSTRACT: A Tiny API client for MetaCPAN
18 use JSON::PP 'encode_json', 'decode_json';
23 my ($class, @args) = @_;
26 or croak 'Arguments must be provided as name/value pairs';
30 die 'ua_args must be an array reference'
31 if $params{ua_args} && ref($params{ua_args}) ne 'ARRAY';
34 base_url => $params{base_url} || 'http://api.metacpan.org/v0',
35 ua => $params{ua} || HTTP::Tiny->new(
38 : (agent => 'MetaCPAN::API::Tiny/'
39 . ($MetaCPAN::API::VERSION || 'xx'))),
42 return bless($self, $class);
45 sub _build_extra_params {
49 or croak 'Incorrect number of params, must be key/value';
54 foreach my $key (keys %extra)
56 # The implementation in HTTP::Tiny uses + instead of %20, fix that
57 $extra{$key} = $ua->_uri_escape($extra{$key});
58 $extra{$key} =~ s/\+/%20/g;
61 my $params = join '&', map { "$_=" . $extra{$_} } sort keys %extra;
67 # /source/{author}/{release}/{path}
70 my %opts = @_ ? @_ : ();
72 my $error = "Provide 'author' and 'release' and 'path'";
74 %opts or croak $error;
77 defined ( my $author = $opts{'author'} ) &&
78 defined ( my $release = $opts{'release'} ) &&
79 defined ( my $path = $opts{'path'} )
81 $url = "source/$author/$release/$path";
86 $url = $self->{base_url} . "/$url";
88 my $result = $self->{ua}->get($url);
90 or croak "Failed to fetch '$url': " . $result->{'reason'};
92 return $result->{'content'};
96 # /release/{distribution}
97 # /release/{author}/{release}
100 my %opts = @_ ? @_ : ();
102 my $error = "Either provide 'distribution', or 'author' and 'release', " .
105 %opts or croak $error;
109 if ( defined ( my $dist = $opts{'distribution'} ) ) {
110 $url = "release/$dist";
112 defined ( my $author = $opts{'author'} ) &&
113 defined ( my $release = $opts{'release'} )
115 $url = "release/$author/$release";
116 } elsif ( defined ( my $search_opts = $opts{'search'} ) ) {
117 ref $search_opts && ref $search_opts eq 'HASH'
120 %extra_opts = %{$search_opts};
121 $url = 'release/_search';
126 return $self->fetch( $url, %extra_opts );
131 # /pod/{author}/{release}/{path}
134 my %opts = @_ ? @_ : ();
136 my $error = "Either provide 'module' or 'author and 'release' and 'path'";
138 %opts or croak $error;
140 if ( defined ( my $module = $opts{'module'} ) ) {
141 $url = "pod/$module";
143 defined ( my $author = $opts{'author'} ) &&
144 defined ( my $release = $opts{'release'} ) &&
145 defined ( my $path = $opts{'path'} )
147 $url = "pod/$author/$release/$path";
154 if ( defined ( my $type = $opts{'content-type'} ) ) {
155 $type =~ m{^ text/ (?: html|plain|x-pod|x-markdown ) $}x
156 or croak 'Incorrect content-type provided';
158 $extra{headers}{'content-type'} = $type;
161 $url = $self->{base_url}. "/$url";
163 my $result = $self->{ua}->get( $url, \%extra );
165 or croak "Failed to fetch '$url': " . $result->{'reason'};
167 return $result->{'content'};
176 $name or croak 'Please provide a module name';
178 return $self->fetch("module/$name");
182 # file() is a synonym of module
183 sub file { goto &module }
189 my ( $pause_id, $url, %extra_opts );
192 $url = 'author/' . shift;
193 } elsif ( @_ == 2 ) {
196 if ( defined $opts{'pauseid'} ) {
197 $url = "author/" . $opts{'pauseid'};
198 } elsif ( defined $opts{'search'} ) {
199 my $search_opts = $opts{'search'};
201 ref $search_opts && ref $search_opts eq 'HASH'
202 or croak "'search' key must be hashref";
204 %extra_opts = %{$search_opts};
205 $url = 'author/_search';
207 croak 'Unknown option given';
210 croak 'Please provide an author PAUSEID or a "search"';
213 return $self->fetch( $url, %extra_opts );
221 my $extra = $self->_build_extra_params(@_);
222 my $base = $self->{base_url};
223 my $req_url = $extra ? "$base/$url?$extra" : "$base/$url";
225 my $result = $self->{ua}->get($req_url);
226 return $self->_decode_result( $result, $req_url );
234 my $base = $self->{base_url};
237 or croak 'First argument of URL must be provided';
239 ref $query and ref $query eq 'HASH'
240 or croak 'Second argument of query hashref must be provided';
242 my $query_json = encode_json( $query );
243 my $result = $self->{ua}->request(
247 headers => { 'Content-Type' => 'application/json' },
248 content => $query_json,
252 return $self->_decode_result( $result, $url, $query_json );
257 my ( $result, $url, $original ) = @_;
260 ref $result and ref $result eq 'HASH'
261 or croak 'First argument must be hashref';
264 or croak 'Second argument of a URL must be provided';
266 if ( defined ( my $success = $result->{'success'} ) ) {
267 my $reason = $result->{'reason'} || '';
268 $reason .= ( defined $original ? " (request: $original)" : '' );
270 $success or croak "Failed to fetch '$url': $reason";
272 croak 'Missing success in return value';
275 defined ( my $content = $result->{'content'} )
276 or croak 'Missing content in return value';
278 eval { $decoded_result = decode_json $content; 1 }
279 or do { croak "Couldn't decode '$content': $@" };
281 return $decoded_result;
292 MetaCPAN::API::Tiny - A Tiny API client for MetaCPAN
300 This is the Tiny version of L<MetaCPAN::API>. It implements a compatible API
301 with a few notable exceptions:
305 =item Attributes are direct hash access
307 The attributes defined using Mo(o|u)se are now accessed via the blessed hash
308 directly. There are no accessors defined to access this elements.
310 =item Exception handling
312 Instead of using Try::Tiny, raw evals are used. This could potentially cause
313 issues, so just be aware.
317 Test::Fatal was replaced with an eval implementation of exception().
318 Test::TinyMocker usage is retained, but may be absorbed since it is pure perl
326 new is the constructor for MetaCPAN::API::Tiny. In the non-tiny version of this
327 module, this is provided via Any::Moose built from the attributes defined. In
328 the tiny version, we define our own constructor. It takes the same arguments
329 and provides similar checks to MetaCPAN::API with regards to arguments passed.
331 =head1 PUBLIC_METHODS
335 my $source = $mcpan->source(
337 release => 'Moose-2.0201',
338 path => 'lib/Moose.pm',
341 Searches MetaCPAN for a module or a specific release and returns the plain source.
345 my $result = $mcpan->release( distribution => 'Moose' );
348 my $result = $mcpan->release( author => 'DOY', release => 'Moose-2.0001' );
350 Searches MetaCPAN for a dist.
352 You can do complex searches using 'search' parameter:
354 # example lifted from MetaCPAN docs
355 my $result = $mcpan->release(
357 author => "OALDERS AND ",
358 filter => "status:latest",
366 my $result = $mcpan->pod( module => 'Moose' );
369 my $result = $mcpan->pod(
371 release => 'Moose-2.0201',
372 path => 'lib/Moose.pm',
375 Searches MetaCPAN for a module or a specific release and returns the POD.
379 my $result = $mcpan->module('MetaCPAN::API');
381 Searches MetaCPAN and returns a module's ".pm" file.
385 A synonym of L</module>
389 my $result1 = $mcpan->author('XSAWYERX');
390 my $result2 = $mcpan->author( pauseid => 'XSAWYERX' );
392 Searches MetaCPAN for a specific author.
394 You can do complex searches using 'search' parameter:
396 # example lifted from MetaCPAN docs
397 my $result = $mcpan->author(
399 q => 'profile.name:twitter',
406 my $result = $mcpan->fetch('/release/distribution/Moose');
409 my $more = $mcpan->fetch(
410 '/release/distribution/Moose',
414 This is a helper method for API implementations. It fetches a path from MetaCPAN, decodes the JSON from the content variable and returns it.
416 You don't really need to use it, but you can in case you want to write your own extension implementation to MetaCPAN::API.
418 It accepts an additional hash as "GET" parameters.
422 # /release&content={"query":{"match_all":{}},"filter":{"prefix":{"archive":"Cache-Cache-1.06"}}}
423 my $result = $mcpan->post(
426 query => { match_all => {} },
427 filter => { prefix => { archive => 'Cache-Cache-1.06' } },
431 The POST equivalent of the "fetch()" method. It gets the path and JSON request.
435 Overall the tests and code were ripped directly from MetaCPAN::API and
436 tiny-fied. A big thanks to Sawyer X for writing the original module.
440 Nicholas R. Perez <nperez@cpan.org>
442 =head1 COPYRIGHT AND LICENSE
444 This software is copyright (c) 2013 by Nicholas R. Perez <nperez@cpan.org>.
446 This is free software; you can redistribute it and/or modify it under
447 the same terms as the Perl 5 programming language system itself.
452 s/^ //mg for values %fatpacked;
455 if (my $fat = $fatpacked{$_[1]}) {
458 return 0 unless length $fat;
459 $fat =~ s/^([^\n]*\n?)//;
464 open my $fh, '<', \$fat
465 or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
471 } # END OF FATPACK CODE
477 use Fatal qw(open close);
482 use Module
::CoreList
;
485 use MetaCPAN
::API
::Tiny
;
487 # Below, 5.024 should be aligned with the version of perl actually
488 # bundled in Buildroot:
489 die <<"MSG" if $] < 5.024;
490 This script needs a host perl with the same major version as Buildroot target perl.
492 Your current host perl is:
496 You may install a local one by running:
497 perlbrew install perl-5.24.0
500 my ($help, $man, $quiet, $force, $recommend, $test, $host);
502 GetOptions
( 'help|?' => \
$help,
504 'quiet|q' => \
$quiet,
505 'force|f' => \
$force,
507 'target!' => \
$target,
508 'recommend' => \
$recommend,
510 ) or pod2usage
(-exitval
=> 1);
511 pod2usage
(-exitval
=> 0) if $help;
512 pod2usage
(-exitval
=> 0, -verbose
=> 2) if $man;
513 pod2usage
(-exitval
=> 1) if scalar @ARGV == 0;
515 my %dist; # name -> metacpan data
516 my %need_target; # name -> 1 if target package is needed
517 my %need_host; # name -> 1 if host package is needed
518 my %need_dlopen; # name -> 1 if requires dynamic library
519 my %deps_build; # name -> list of host dependencies
520 my %deps_runtime; # name -> list of target dependencies
521 my %deps_optional; # name -> list of optional target dependencies
522 my %license_files; # name -> list of license files
523 my %checksum; # author -> list of checksum
524 my $mcpan = MetaCPAN
::API
::Tiny
->new();
525 my $ua = HTTP
::Tiny
->new();
529 my($path) = $url =~ m
|^[^:/?#]+://[^/?
#]*([^?#]*)|;
530 my($basename, $dirname) = fileparse
( $path );
531 unless ($checksum{$dirname}) {
532 my $response = $ua->get(qq{http
://cpan
.metacpan
.org
${dirname
}CHECKSUMS
});
533 $checksum{$dirname} = $response->{content
};
535 my $chksum = Safe
->new->reval($checksum{$dirname});
536 return $chksum->{$basename}, $basename;
540 my ($author, $distname, $version) = @_;
541 my $url = qq{http
://api.metacpan
.org
/source/${author
}/${distname}-${version}/MANIFEST
};
542 my $response = $ua->get($url);
543 return $response->{content
};
548 # This heuristic determines if a module is a native extension, by searching
549 # some file extension types in the MANIFEST of the distribution.
550 # It was inspired by http://deps.cpantesters.org/static/purity.html
551 return $manifest =~ m/\.(swg|xs|c|h|i)[\n\s]/;
554 sub find_license_files
{
557 foreach (split /\n/, $manifest) {
559 push @license_files, $_ if m/(ARTISTIC|COPYING|COPYRIGHT|LICENSE)/i;
561 if (scalar @license_files == 0 && $manifest =~ m/(README)[\n\s]/i) {
562 @license_files = ($1);
564 return \
@license_files;
568 my ($name, $need_target, $need_host, $top) = @_;
569 $need_target{$name} = $need_target if $need_target;
570 $need_host{$name} = $need_host if $need_host;
571 unless ($dist{$name} && !$top) {
572 say qq{fetch
${name
}} unless $quiet;
573 my $result = $mcpan->release( distribution
=> $name );
574 $dist{$name} = $result;
575 my $manifest = get_manifest
( $result->{author
}, $name, $result->{version
} );
576 $need_dlopen{$name} = is_xs
( $manifest );
577 $license_files{$name} = find_license_files
( $manifest );
581 foreach my $dep (@
{$result->{dependency
}}) {
582 my $modname = ${$dep}{module
};
583 next if $modname eq q{perl};
584 next if $modname =~ m
|^Alien
|;
585 next if $modname =~ m
|^Win32
|;
586 next if !($test && $top) && $modname =~ m
|^Test
|;
587 next if Module
::CoreList
::is_core
( $modname, undef, $] );
588 # we could use the host Module::CoreList data, because host perl and
589 # target perl have the same major version
590 next if ${$dep}{phase
} eq q{develop};
591 next if !($test && $top) && ${$dep}{phase
} eq q{test};
592 my $distname = $mcpan->module( $modname )->{distribution
};
593 if (${$dep}{phase
} eq q{runtime}) {
594 if (${$dep}{relationship
} eq q{requires}) {
595 $runtime{$distname} = 1;
598 $optional{$distname} = 1 if $recommend && $top;
601 else { # configure, build
602 $build{$distname} = 1;
605 $deps_build{$name} = [keys %build];
606 $deps_runtime{$name} = [keys %runtime];
607 $deps_optional{$name} = [keys %optional];
608 foreach my $distname (@
{$deps_build{$name}}) {
609 fetch
( $distname, 0, 1 );
611 foreach my $distname (@
{$deps_runtime{$name}}) {
612 fetch
( $distname, $need_target, $need_host );
613 $need_dlopen{$name} ||= $need_dlopen{$distname};
615 foreach my $distname (@
{$deps_optional{$name}}) {
616 fetch
( $distname, $need_target, $need_host );
622 foreach my $distname (@ARGV) {
623 # Command-line's distributions
624 fetch
( $distname, !!$target, !!$host, 1 );
626 say scalar keys %dist, q{ packages fetched.} unless $quiet;
628 # Buildroot package name: lowercase
632 return q{perl-} . lc $name;
635 # Buildroot variable name: uppercase
642 while (my ($distname, $dist) = each %dist) {
643 my $fsname = fsname
( $distname );
644 my $dirname = q{package/} . $fsname;
645 my $cfgname = $dirname . q{/Config.in};
646 my $mkname = $dirname . q{/} . $fsname . q{.mk};
647 my $hashname = $dirname . q{/} . $fsname . q{.hash};
648 my $brname = brname
( $fsname );
649 mkdir $dirname unless -d
$dirname;
650 if ($need_target{$distname} && ($force || !-f
$cfgname)) {
651 my $abstract = $dist->{abstract
};
652 my $homepage = $dist->{resources
}->{homepage
} || qq{https
://metacpan
.org
/release/${distname
}};
653 say qq{write ${cfgname
}} unless $quiet;
654 open my $fh, q{>}, $cfgname;
655 say {$fh} qq{config BR2_PACKAGE_
${brname
}};
656 say {$fh} qq{\tbool
"${fsname}"};
657 say {$fh} qq{\tdepends on
!BR2_STATIC_LIBS
} if $need_dlopen{$distname};
658 foreach my $dep (sort @
{$deps_runtime{$distname}}) {
659 my $brdep = brname
( fsname
( $dep ) );
660 say {$fh} qq{\tselect BR2_PACKAGE_
${brdep
}};
662 say {$fh} qq{\thelp
};
663 say {$fh} qq{\t ${abstract
}\n} if $abstract;
664 say {$fh} qq{\t ${homepage
}};
665 if ($need_dlopen{$distname}) {
666 say {$fh} qq{\ncomment
"${fsname} needs a toolchain w/ dynamic library"};
667 say {$fh} qq{\tdepends on BR2_STATIC_LIBS
};
671 if ($force || !-f
$mkname) {
672 my $version = $dist->{version
};
673 my($path) = $dist->{download_url
} =~ m
|^[^:/?#]+://[^/?
#]*([^?#]*)|;
674 # this URL contains only the scheme, auth and path parts (but no query and fragment parts)
675 # the scheme is not used, because the job is done by the BR download infrastructure
676 # the auth part is not used, because we use $(BR2_CPAN_MIRROR)
677 my($filename, $directories, $suffix) = fileparse
( $path, q{tar.gz}, q{tgz} );
678 $directories =~ s
|/$||;
679 my $dependencies = join q{ }, map( { q{host-} . fsname
( $_ ); } sort @
{$deps_build{$distname}} ),
680 map( { fsname
( $_ ); } sort @
{$deps_runtime{$distname}} );
681 my $host_dependencies = join q{ }, map { q{host-} . fsname
( $_ ); } sort( @
{$deps_build{$distname}},
682 @
{$deps_runtime{$distname}} );
683 my $license = ref $dist->{license
} eq 'ARRAY'
684 ?
join q{ or }, @
{$dist->{license
}}
686 # BR requires license name as in http://spdx.org/licenses/
687 $license =~ s
|apache_2_0
|Apache
-2.0|;
688 $license =~ s
|artistic_2
|Artistic
-2.0|;
689 $license =~ s
|mit
|MIT
|;
690 $license =~ s
|openssl
|OpenSSL
|;
691 $license =~ s
|perl_5
|Artistic
or GPLv1
+|;
692 my $license_files = join q{ }, @
{$license_files{$distname}};
693 say qq{write ${mkname
}} unless $quiet;
694 open my $fh, q{>}, $mkname;
695 say {$fh} qq{################################################################################};
697 say {$fh} qq{# ${fsname}};
699 say {$fh} qq{################################################################################};
701 say {$fh} qq{${brname
}_VERSION
= ${version
}};
702 say {$fh} qq{${brname
}_SOURCE
= ${distname
}-\
$(${brname
}_VERSION
).${suffix
}};
703 say {$fh} qq{${brname
}_SITE
= \
$(BR2_CPAN_MIRROR
)${directories
}};
704 say {$fh} qq{${brname
}_DEPENDENCIES
= ${dependencies
}} if $need_target{$distname} && $dependencies;
705 say {$fh} qq{HOST_
${brname
}_DEPENDENCIES
= ${host_dependencies
}} if $need_host{$distname} && $host_dependencies;
706 say {$fh} qq{${brname
}_LICENSE
= ${license
}} if $license && $license ne q{unknown};
707 say {$fh} qq{${brname
}_LICENSE_FILES
= ${license_files
}} if $license_files;
709 foreach (sort @
{$deps_optional{$distname}}) {
710 next if grep { $_ eq $distname; } @
{$deps_runtime{$_}}; # avoid cyclic dependencies
711 my $opt_brname = brname
( $_ );
712 my $opt_fsname = fsname
( $_ );
713 say {$fh} qq{ifeq
(\
$(BR2_PACKAGE_PERL_
${opt_brname
}),y
)};
714 say {$fh} qq{${brname
}_DEPENDENCIES
+= ${opt_fsname
}};
718 say {$fh} qq{\
$(eval \
$(perl
-package))} if $need_target{$distname};
719 say {$fh} qq{\
$(eval \
$(host
-perl
-package))} if $need_host{$distname};
722 if ($force || !-f
$hashname) {
723 my($checksum, $filename) = get_checksum
($dist->{download_url
});
724 my $md5 = $checksum->{md5
};
725 my $sha256 = $checksum->{sha256
};
726 say qq{write ${hashname
}} unless $quiet;
727 open my $fh, q{>}, $hashname;
728 say {$fh} qq{# retrieved by scancpan from http://cpan.metacpan.org/};
729 say {$fh} qq{md5
${md5
} ${filename
}};
730 say {$fh} qq{sha256
${sha256
} ${filename
}};
736 my $cfgname = q{package/Config.in};
738 open my $fh, q{<}, $cfgname;
741 $pkg{$_} = 1 if m
|package/perl
-|;
746 foreach my $distname (keys %need_target) {
747 my $fsname = fsname
( $distname );
748 $pkg{qq{\tsource
"package/${fsname}/Config.in"}} = 1;
751 say qq{${cfgname
} must contain the following lines
:};
752 say join qq{\n}, sort keys %pkg;
758 support/scripts/scancpan Try-Tiny Moo
762 supports/scripts/scancpan [options] [distname ...]
780 Prints a brief help message and exits.
784 Prints the manual page and exits.
788 Executes without output
792 Forces the overwriting of existing files.
794 =item B<-target/-notarget>
796 Switches package generation for the target variant (the default is C<-target>).
798 =item B<-host/-nohost>
800 Switches package generation for the host variant (the default is C<-nohost>).
804 Adds I<recommended> dependencies.
808 Adds dependencies for test.
814 This script creates templates of the Buildroot package files for all the
815 Perl/CPAN distributions required by the specified distnames. The
816 dependencies and metadata are fetched from https://metacpan.org/.
818 After running this script, it is necessary to check the generated files.
819 You have to manually add the license files (PERL_FOO_LICENSE_FILES variable).
820 For distributions that link against a target library, you have to add the
821 buildroot package name for that library to the DEPENDENCIES variable.
823 See the Buildroot documentation for details on the usage of the Perl
826 The major version of the host perl must be aligned on the target one,
827 in order to work with the right CoreList data.
831 Copyright (C) 2013-2016 by Francois Perrad <francois.perrad@gadz.org>
833 This program is free software; you can redistribute it and/or modify
834 it under the terms of the GNU General Public License as published by
835 the Free Software Foundation; either version 2 of the License, or
836 (at your option) any later version.
838 This program is distributed in the hope that it will be useful,
839 but WITHOUT ANY WARRANTY; without even the implied warranty of
840 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
841 General Public License for more details.
843 You should have received a copy of the GNU General Public License
844 along with this program; if not, write to the Free Software
845 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
847 This script is a part of Buildroot.
849 This script requires the module C<MetaCPAN::API::Tiny> (version 1.131730)
850 which was included at the beginning of this file by the tool C<fatpack>.
852 See L<http://search.cpan.org/~nperez/MetaCPAN-API-Tiny-1.131730/>.
854 See L<http://search.cpan.org/search?query=App-FatPacker&mode=dist>.
856 These both libraries are free software and may be distributed under the same
857 terms as perl itself.
859 And perl may be distributed under the terms of Artistic v1 or GPL v1 license.