blib/lib/CPAN/Perl/Releases/MetaCPAN.pm

filter: Statementstmt 25.0% 20 / 80 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 5 totaltotal 20.1% 26 / 129 CC 16 SCAR 40.5
CC
16
Cov
18%
get
132.0
new
12.0
_self
12.0
CRAP 57.3
↑ Summary
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'
l!l
00
MC/DC0%0/1
$option{'uri'} || 'https://fastapi.metacpan.org/v1/release'
$option{'uri'}
Truth table0%0/2
A
A= $option{'uri'}
Aresult
11
00
16 0 $uri =~ s{/$}{};
17 0 ▶ my $cache = exists $option{cache} ? $option{cache} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'cache'} ? : 0 0 0
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
BranchTrueFalseTotal
if $self->{"cache"} and $self->{"_releases"} 0 0 0
Condition0%0/3
$self->{"cache"} and $self->{"_releases"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
53 0 ▶ my $message = $res->{status} == 599 ? ", $res->{content}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$res->{'status'} == 599 ? : 0 0 0
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
BranchTrueFalseTotal
unless defined $total 0 0 0
ref $hash->{'hits'}{'total'} ? : 0 0 0
60 0 push @release, map { $_->{fields} } @{$hash->{hits}{hits}};
61 0 ▶ last if $total <= @release;
Branch: 1 branch
BranchTrueFalseTotal
if $total <= @release 0 0 0
62 0 $from = @release;
63 }
64 0 ▶ if ($total != @release) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total != @release) 0 0 0
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
BranchTrueFalseTotal
if $self->{"cache"} 0 0 0
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
BranchTrueFalseTotal
eval { do { $args[0]->isa(__PACKAGE__) } } ? : 0 0 0
74 0 ▶ wantarray ? ($self, @args) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
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
BranchTrueFalseTotal
if ($url =~ /\.(tar\.\S+)$/u) { } 0 0 0
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__
↑ Summary