Repository.pm

filter: Statementstmt 100% 70 / 70 Branchbran 70.0% 14 / 20 Conditioncond 53.3% 8 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 84.8% 112 / 132 CC 21 SCAR 12.9
CC
21
Cov
88%
_check_uri
6.0
list
5.0
BUILDARGS
4.1
CRAP 3.6
« Repository/Source.pm ↑ Summary
1 package OPM::Repository;
2  
3 # ABSTRACT: parse OPM repositories' framework.xml files to search for add ons
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '1.0.0'; # VERSION
9  
10 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use List::Util qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Regexp::Common qw(URI);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use OPM::Repository::Source;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 our $ALLOWED_SCHEME = [ 'HTTP', 'file' ];
18  
19 4 ▶has sources => ( is => 'ro', required => 1, isa => sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
20 die "no valid URIs" unless
21 ref $_[0] eq 'ARRAY'
22 and
23 4 ▶ all { _check_uri( $_ ) } @{ $_[0] }
Subroutine __ANON__: called CC=1 SCAR=0.5
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" and &all(sub { _check_uri($_); } , @{$_[0];}) 0 4 4
Condition33%1/3
ref $_[0] eq "ARRAY" and &all(sub { _check_uri($_); } , @{$_[0];})
!ll&&!rl&&r
004
MC/DC0%0/2
ref $_[0] eq "ARRAY" and &all(sub { _check_uri($_); } , @{$_[0];})
ref $_[0] eq "ARRAY" &all(sub { _check_uri($_); } , @{$_[0];})
Truth table33%1/3
A and B
A= ref $_[0] eq "ARRAY"B= &all(sub { _check_uri($_); } , @{$_[0];})
ABresult
0X0
100
111
24 4 });
25  
26 4 ▶has _objects => ( is => 'ro', isa => sub {
Subroutine __ANON__: called CC=3 SCAR=12.7
27 die "no valid objects" unless
28 ref $_[0] eq 'ARRAY'
29 and
30 4 ▶ all { blessed $_ and $_->isa( 'OPM::Repository::Source' ) } @{ $_[0] }
Subroutine __ANON__: called CC=2 SCAR=8.1
Branch: 2 branches
BranchTrueFalseTotal
unless ref $_[0] eq "ARRAY" and &all(sub { builtin::blessed($_) and $_->isa("OPM::Repository::Source"); } , @{$_[0];}) 0 4 4
builtin::blessed($_) and $_->isa("OPM::Repository::Source") 5 0 5
Condition33%1/3
ref $_[0] eq "ARRAY" and &all(sub { builtin::blessed($_) and $_->isa("OPM::Repository::Source"); } , @{$_[0];})
!ll&&!rl&&r
004
MC/DC0%0/2
ref $_[0] eq "ARRAY" and &all(sub { builtin::blessed($_) and $_->isa("OPM::Repository::Source"); } , @{$_[0];})
ref $_[0] eq "ARRAY" &all(sub { builtin::blessed($_) and $_->isa("OPM::Repository::Source"); } , @{$_[0];})
Truth table33%1/3
A and B
A= ref $_[0] eq "ARRAY"B= &all(sub { builtin::blessed($_) and $_->isa("OPM::Repository::Source"); } , @{$_[0];})
ABresult
0X0
100
111
31 4 });
32  
33 9 ▶sub find {
Subroutine find: called CC=4 SCAR=13.9
Pod documented
34 9 my ($self, %params) = @_;
35  
36 9 my @found;
37 9 ▶ for my $source ( @{ $self->_objects || [] } ) {
Condition50%1/2
$self->_objects || []
l!l
90
MC/DC0%0/1
$self->_objects || []
$self->_objects
Truth table50%1/2
A
A= $self->_objects
Aresult
11
00
38 12 my $found = $source->find( %params );
39 12 ▶ push @found, $found if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 4 8 12
40 }
41  
42 9 return @found;
43 }
44  
45 4 ▶sub list {
Subroutine list: called CC=5 SCAR=16.1
Pod documented
46 4 my ($self, %params) = @_;
47  
48 4 my %found_packages;
49 my @detailed_list;
50 4 ▶ for my $source ( @{ $self->_objects || [] } ) {
Condition50%1/2
$self->_objects || []
l!l
40
MC/DC0%0/1
$self->_objects || []
$self->_objects
Truth table50%1/2
A
A= $self->_objects
Aresult
11
00
51 4 my @found = $source->list( %params );
52 4 @found_packages{@found} = (1) x @found;
53 4 push @detailed_list, @found;
54 }
55  
56 4 my @packages;
57 4 ▶ if ( $params{details} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'details'}) { } 2 2 4
58 2 ▶ @packages = sort { $a->{name} cmp $b->{name} || $a->{version} cmp $b->{version} }@detailed_list;
Condition100%3/3
$OPM::Repository::a->{'name'} cmp $OPM::Repository::b->{'name'} || $OPM::Repository::a->{'version'} cmp $OPM::Repository::b->{'version'}
l!l&&r!l&&!r
168823
MC/DC100%2/2
$OPM::Repository::a->{'name'} cmp $OPM::Repository::b->{'name'} || $OPM::Repository::a->{'version'} cmp $OPM::Repository::b->{'version'}
$OPM::Repository::a->{'name'} cmp $OPM::Repository::b->{'name'} $OPM::Repository::a->{'version'} cmp $OPM::Repository::b->{'version'}
Truth table100%3/3
A || B
A= $OPM::Repository::a->{'name'} cmp $OPM::Repository::b->{'name'}B= $OPM::Repository::a->{'version'} cmp $OPM::Repository::b->{'version'}
ABresult
1X1
011
000
59 }
60 else {
61 2 @packages = sort keys %found_packages;
62 }
63  
64 4 return @packages;
65 }
66  
67 4 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=14.0
Pod documented
68 4 my ($class, @args) = @_;
69  
70 4 ▶ unshift @args, 'sources' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 4 4
71  
72 4 my %param = @args;
73  
74 4 ▶ for my $url ( @{ $param{sources} || [] } ) {
Condition50%1/2
$param{'sources'} || []
l!l
40
MC/DC0%0/1
$param{'sources'} || []
$param{'sources'}
Truth table50%1/2
A
A= $param{'sources'}
Aresult
11
00
75 5 push @{ $param{_objects} }, OPM::Repository::Source->new( url => $url );
76 }
77  
78 4 return \%param;
79 }
80  
81 5 ▶sub _check_uri {
Subroutine _check_uri: called CC=6 SCAR=18.0
82 5 ▶ my @allowed_schemes = ref $ALLOWED_SCHEME ? @{ $ALLOWED_SCHEME } : $ALLOWED_SCHEME;
Branch: 1 branch
BranchTrueFalseTotal
ref $OPM::Repository::ALLOWED_SCHEME ? : 5 0 5
83  
84 5 my $matches;
85  
86 SCHEME:
87 5 for my $scheme ( @allowed_schemes ) {
88 my $regex = ( lc $scheme eq 'http' ) ?
89 $RE{URI}{HTTP}{-scheme => qr/https?/} :
90 10 ▶ $RE{URI}{$scheme};
Branch: 1 branch
BranchTrueFalseTotal
lc $scheme eq 'http' ? : 5 5 10
91  
92 10 ▶ if ( $_[0] =~ m{\A$regex\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\A$regex\z/) 5 5 10
93 5 $matches++;
94 5 last SCHEME;
95 }
96 }
97  
98 5 ▶ die "No valid URI" unless $matches;
Branch: 1 branch
BranchTrueFalseTotal
unless $matches 0 5 5
99 5 return 1;
100 }
101  
102 4 1;
103  
104 __END__
« Repository/Source.pm ↑ Summary