| 1 | package CPAN::Perl::Releases::MetaCPAN v1.0.1; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use experimental qw(lexical_subs signatures); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $TRIAL = 0; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Tinyish; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT_OK = qw(perl_tarballs perl_versions perl_pumpkins); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | ▶ | sub new ($class, %option) { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $uri = $option{uri} || "https://fastapi.metacpan.org/v1/release"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$option{'uri'} || 'https://fastapi.metacpan.org/v1/release'
MC/DC0%0/1
$option{'uri'} || 'https://fastapi.metacpan.org/v1/release'
$option{'uri'}
Truth table0%0/2
A
A= $option{'uri'}
| |||||||||||||||||||||||||||||
| 16 | 0 | $uri =~ s{/$}{}; | |||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $cache = exists $option{cache} ? $option{cache} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | my $http = HTTP::Tinyish->new(verify_SSL => 1, agent => __PACKAGE__ . "/" . __PACKAGE__->VERSION); | |||||||||||||||||||||||||||
| 19 | 0 | my $json = JSON::PP->new->canonical(1); | |||||||||||||||||||||||||||
| 20 | 0 | bless { uri => $uri, http => $http, cache => $cache, json => $json }, $class; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub get ($self) { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $self->{_releases} if $self->{cache} and $self->{_releases}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"cache"} and $self->{"_releases"}
MC/DC0%0/2
$self->{"cache"} and $self->{"_releases"}
$self->{"cache"}
$self->{"_releases"}
Truth table0%0/3
A and B
A= $self->{"cache"}B= $self->{"_releases"}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | my @release; | |||||||||||||||||||||||||||
| 27 | 0 | my $from = 0; | |||||||||||||||||||||||||||
| 28 | 0 | my $total; | |||||||||||||||||||||||||||
| 29 | 0 | my $uri = "$self->{uri}/_search"; | |||||||||||||||||||||||||||
| 30 | 0 | for (1..5) { | |||||||||||||||||||||||||||
| 31 | # https://github.com/metacpan/metacpan-web/blob/master/lib/MetaCPAN/Web/Model/API/Release.pm | ||||||||||||||||||||||||||||
| 32 | # https://github.com/metacpan/metacpan-api/blob/master/lib/MetaCPAN/Document/Release/Set.pm | ||||||||||||||||||||||||||||
| 33 | 0 | my $query = { | |||||||||||||||||||||||||||
| 34 | query => { | ||||||||||||||||||||||||||||
| 35 | bool => { | ||||||||||||||||||||||||||||
| 36 | must => [ | ||||||||||||||||||||||||||||
| 37 | { term => { distribution => "perl" } }, | ||||||||||||||||||||||||||||
| 38 | { term => { authorized => JSON::PP::true } }, | ||||||||||||||||||||||||||||
| 39 | ], | ||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | size => 1000, | ||||||||||||||||||||||||||||
| 43 | from => $from, | ||||||||||||||||||||||||||||
| 44 | sort => [ { date => 'desc' } ], | ||||||||||||||||||||||||||||
| 45 | fields => [qw( name date author version status maturity download_url checksum_sha256 )], | ||||||||||||||||||||||||||||
| 46 | _source => JSON::PP::false, | ||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||
| 48 | my $res = $self->{http}->post($uri, { | ||||||||||||||||||||||||||||
| 49 | 0 | content => $self->{json}->encode($query), | |||||||||||||||||||||||||||
| 50 | headers => { 'content-type' => 'application/json' }, | ||||||||||||||||||||||||||||
| 51 | }); | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (!$res->{success}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $message = $res->{status} == 599 ? ", $res->{content}" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | chomp $message; | |||||||||||||||||||||||||||
| 55 | 0 | $message =~ s/\n/ /g; | |||||||||||||||||||||||||||
| 56 | 0 | die "$res->{status} $res->{reason}, $uri$message\n"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 0 | my $hash = $self->{json}->decode($res->{content}); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | $total = ref $hash->{hits}{total} ? $hash->{hits}{total}{value} : $hash->{hits}{total} unless defined $total; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 60 | 0 | push @release, map { $_->{fields} } @{$hash->{hits}{hits}}; | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | last if $total <= @release; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | $from = @release; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($total != @release) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | die sprintf "metacpan returns %d perl releases, but expected %d\n", | |||||||||||||||||||||||||||
| 66 | (scalar @release), $total; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $self->{_releases} = \@release if $self->{cache}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | \@release; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _self (@args) { | ||||||||||||||||||||||||||
|
Subroutine
_self: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $self = eval { $args[0]->isa(__PACKAGE__) } ? shift @args : __PACKAGE__->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | wantarray ? ($self, @args) : $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub perl_tarballs (@args) { | ||||||||||||||||||||||||||
|
Subroutine
perl_tarballs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ($self, $arg) = _self(@args); | |||||||||||||||||||||||||||
| 79 | 0 | my $releases = $self->get; | |||||||||||||||||||||||||||
| 80 | my %tarballs = | ||||||||||||||||||||||||||||
| 81 | map { | ||||||||||||||||||||||||||||
| 82 | 0 | my $url = $_->{download_url}; | |||||||||||||||||||||||||||
| 83 | 0 | $url =~ s{.*authors/id/}{}; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($url =~ /\.(tar\.\S+)$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ($1, $url); | |||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | 0 | (); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | grep { my $name = $_->{name}; $name =~ s/^perl-?//; $name eq $arg } | |||||||||||||||||||||||||||
| 91 | 0 | grep { $_->{status} =~ /^(?:cpan|latest)$/ } | |||||||||||||||||||||||||||
| 92 | $releases->@*; | ||||||||||||||||||||||||||||
| 93 | 0 | \%tarballs; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub perl_versions (@args) { | ||||||||||||||||||||||||||
|
Subroutine
perl_versions: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = _self(@args); | |||||||||||||||||||||||||||
| 98 | 0 | my $releases = $self->get; | |||||||||||||||||||||||||||
| 99 | my @versions = | ||||||||||||||||||||||||||||
| 100 | 0 | map { my $name = $_->{name}; $name =~ s/^perl-?//; $name } | |||||||||||||||||||||||||||
| 101 | 0 | grep { $_->{status} =~ /^(?:cpan|latest)$/ } | |||||||||||||||||||||||||||
| 102 | $releases->@*; | ||||||||||||||||||||||||||||
| 103 | 0 | @versions; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub perl_pumpkins (@args) { | ||||||||||||||||||||||||||
|
Subroutine
perl_pumpkins: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 0 | my $self = _self(@args); | |||||||||||||||||||||||||||
| 108 | 0 | my $releases = $self->get; | |||||||||||||||||||||||||||
| 109 | my %author = | ||||||||||||||||||||||||||||
| 110 | 0 | map { $_->{author} => 1 } | |||||||||||||||||||||||||||
| 111 | 0 | grep { $_->{status} =~ /^(?:cpan|latest)$/ } | |||||||||||||||||||||||||||
| 112 | $releases->@*; | ||||||||||||||||||||||||||||
| 113 | 0 | sort keys %author; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | 1; | |||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||