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

filter: Statementstmt 22.5% 18 / 80 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 45.4% 5 / 11 Podpod 0.0% 0 / 5 totaltotal 17.9% 23 / 128 CC 16 SCAR 40.8
CC
16
Cov
17%
get
132.0
new
12.0
_self
12.0
CRAP 59.4
↑ Summary Build »
1 package CPAN::Perl::Releases::MetaCPAN;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = '0.010';
6 1 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTTP::Tinyish;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our @EXPORT_OK = qw(perl_tarballs perl_versions perl_pumpkins);
11  
12 sub new {
13 0 ▶ my ($class, %option) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
14 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
15 0 $uri =~ s{/$}{};
16 0 ▶ my $cache = exists $option{cache} ? $option{cache} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'cache'} ? : 0 0 0
17 0 my $http = HTTP::Tinyish->new(verify_SSL => 1, agent => __PACKAGE__ . "/$VERSION");
18 0 my $json = JSON::PP->new->canonical(1);
19 0 bless { uri => $uri, http => $http, cache => $cache, json => $json }, $class;
20 }
21  
22 sub get {
23 0 ▶ my $self = shift;
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 };
47 my $res = $self->{http}->post($uri, {
48 0 content => $self->{json}->encode($query),
49 headers => { 'content-type' => 'application/json' },
50 });
51 0 ▶ if (!$res->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
52 0 ▶ my $message = $res->{status} == 599 ? ", $res->{content}" : "";
Branch: 1 branch
BranchTrueFalseTotal
$res->{'status'} == 599 ? : 0 0 0
53 0 chomp $message;
54 0 $message =~ s/\n/ /g;
55 0 die "$res->{status} $res->{reason}, $uri$message\n";
56 }
57 0 my $hash = $self->{json}->decode($res->{content});
58 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
59 0 push @release, map { $_->{fields} } @{$hash->{hits}{hits}};
60 0 ▶ last if $total <= @release;
Branch: 1 branch
BranchTrueFalseTotal
if $total <= @release 0 0 0
61 0 $from = @release;
62 }
63 0 ▶ if ($total != @release) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total != @release) 0 0 0
64 0 die sprintf "metacpan returns %d perl releases, but expected %d\n",
65 (scalar @release), $total;
66 }
67 0 ▶ $self->{_releases} = \@release if $self->{cache};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cache"} 0 0 0
68 0 \@release;
69 }
70  
71 sub _self {
72 0 ▶ my $self = eval { $_[0]->isa(__PACKAGE__) } ? shift : __PACKAGE__->new;
Subroutine _self: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $_[0]->isa(__PACKAGE__) } } ? : 0 0 0
73 0 ▶ wantarray ? ($self, @_) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
74 }
75  
76 sub perl_tarballs {
77 0 ▶ my ($self, $arg) = _self @_;
Subroutine perl_tarballs: not called CC=2 SCAR=17.9
Pod undocumented
78 0 my $releases = $self->get;
79 my %tarballs =
80 map {
81 0 my $url = $_->{download_url};
82 0 $url =~ s{.*authors/id/}{};
83 0 ▶ if ($url =~ /\.(tar\.\S+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /\.(tar\.\S+)$/) { } 0 0 0
84 0 ($1, $url);
85 } else {
86 0 ();
87 }
88 }
89 0 grep { my $name = $_->{name}; $name =~ s/^perl-?//; $name eq $arg }
90 0 grep { $_->{status} =~ /^(?:cpan|latest)$/ }
91 @$releases;
92 0 \%tarballs;
93 }
94  
95 sub perl_versions {
96 0 ▶ my $self = _self @_;
Subroutine perl_versions: not called CC=1 SCAR=6.9
Pod undocumented
97 0 my $releases = $self->get;
98 my @versions =
99 0 map { my $name = $_->{name}; $name =~ s/^perl-?//; $name }
100 0 grep { $_->{status} =~ /^(?:cpan|latest)$/ }
101 @$releases;
102 0 @versions;
103 }
104  
105 sub perl_pumpkins {
106 0 ▶ my $self = _self @_;
Subroutine perl_pumpkins: not called CC=1 SCAR=6.9
Pod undocumented
107 0 my $releases = $self->get;
108 my %author =
109 0 map { $_->{author} => 1 }
110 0 grep { $_->{status} =~ /^(?:cpan|latest)$/ }
111 @$releases;
112 0 sort keys %author;
113 }
114  
115 1 1;
116 __END__
↑ Summary Build »