blib/lib/Pinto/Target/Package.pm

filter: Statementstmt 92.0% 69 / 75 Branchbran 66.6% 12 / 18 Conditioncond 76.9% 10 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 85.0% 17 / 20 Podpod 57.1% 4 / 7 totaltotal 82.2% 116 / 141 CC 15 SCAR 14.6
CC
15
Cov
86%
gte
12.0
is_core
8.1
__ANON__
5.0
CRAP 4.3
« blib/lib/Pinto/Target.pm ↑ Summary blib/lib/Pinto/Store.pm »
1 # ABSTRACT: Specifies a package by name and version
2  
3 package Pinto::Target::Package;
4  
5 68 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 68 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 68 ▶use MooseX::Types::Moose qw(Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 68 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 68 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 68 ▶use CPAN::Meta::Requirements;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 68 ▶use Pinto::Types qw(Version);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 68 ▶use Pinto::Util qw(throw trim_text);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 68 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 68 ▶use overload ( '""' => 'to_string');
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #------------------------------------------------------------------------------
20  
21 68 our $VERSION = '0.14'; # VERSION
22  
23 #------------------------------------------------------------------------------
24  
25 68 has name => (
26 is => 'ro',
27 isa => Str,
28 required => 1,
29 );
30  
31 68 has version => (
32 is => 'ro',
33 isa => Str | Version,
34 default => '0',
35 coerce => 1,
36 );
37  
38 68 has _vreq => (
39 is => 'ro',
40 isa => 'CPAN::Meta::Requirements',
41 writer => '_set_vreq',
42 init_arg => undef,
43 );
44  
45 #------------------------------------------------------------------------------
46  
47 49 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
48 49 my $orig = shift;
49 49 my $class = shift;
50  
51 49 my @args = @_;
52  
53 49 ▶ if ( @args == 1 and not ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args == 1 and not ref $args[0]) 43 6 49
Condition66%2/3
@args == 1 and not ref $args[0]
!ll&&!rl&&r
6043
MC/DC50%1/2
@args == 1 and not ref $args[0]
@args == 1 not ref $args[0]
Truth table66%2/3
A and not(B)
A= @args == 1B= not ref $args[0]
ABresult
0X0
100
111
54  
55 43 ▶ throw "Invalid package specification: $_[0]"
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^ ([A-Z0-9_:]+) (?:~)? (.*)/xi 0 43 43
56 unless $_[0] =~ m{^ ([A-Z0-9_:]+) (?:~)? (.*)}ix;
57  
58 43 my ($name, $version) = ($1, $2);
59 43 $version =~ s/^\@/==/; # Allow "@" as a synonym for "=="
60 43 ▶ @args = ( name => $name, version => trim_text($version) || 0 );
Condition100%2/2
trim_text($version) || 0
l!l
2617
MC/DC100%1/1
trim_text($version) || 0
trim_text($version)
Truth table100%2/2
A
A= trim_text($version)
Aresult
11
00
61 }
62  
63 49 return $class->$orig(@args);
64 68 };
65  
66 #------------------------------------------------------------------------------
67  
68 49 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
69 49 my $self = shift;
70  
71 # We want to construct the C::M::Requirements object right away to ensure
72 # $self->version is a valid string. But if we do this in a builder, it
73 # has to be lazy because it depends on other attributes. So instead, we
74 # construct it during the BUILD and use a private writer to set it.
75  
76 49 my $args = {$self->name => $self->version};
77  
78 49 ▶ my $req = try { CPAN::Meta::Requirements->from_string_hash( $args) }
Subroutine __ANON__: called CC=1 SCAR=0.0
79 0 ▶ catch { throw "Invalid package target ($self): $_" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
80  
81 49 $self->_set_vreq($req);
82 49 return $self;
83 }
84  
85 #------------------------------------------------------------------------------
86  
87  
88 11 ▶sub is_core {
Subroutine is_core: called CC=8 SCAR=20.9
Pod documented
89 11 my ( $self, %args ) = @_;
90  
91 ## no critic qw(PackageVar);
92  
93 # Note: $PERL_VERSION is broken on old perls, so we must make
94 # our own version object from the old $] variable
95 11 ▶ my $pv = version->parse( $args{in} ) || version->parse($]);
Condition66%2/3
'version'->parse($args{'in'}) || 'version'->parse($])
l!l&&r!l&&!r
920
MC/DC0%0/2
'version'->parse($args{'in'}) || 'version'->parse($])
'version'->parse($args{'in'}) 'version'->parse($])
Truth table66%2/3
A || B
A= 'version'->parse($args{'in'})B= 'version'->parse($])
ABresult
1X1
011
000
96  
97 # If it ain't in here, it ain't in the core
98 11 my $core_modules = $Module::CoreList::version{ $pv->numify + 0 };
99 11 ▶ throw "Invalid perl version $pv" if not $core_modules;
Branch: 1 branch
BranchTrueFalseTotal
unless $core_modules 0 11 11
100 11 ▶ return 0 if not exists $core_modules->{ $self->name };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$core_modules{$self->name} 6 5 11
101  
102 # We treat deprecated modules as if they have already been removed
103 5 my $deprecated_modules = $Module::CoreList::deprecated{ $pv->numify + 0 };
104 5 ▶ return 0 if $deprecated_modules && exists $deprecated_modules->{ $self->name };
Branch: 1 branch
BranchTrueFalseTotal
if $deprecated_modules and exists $$deprecated_modules{$self->name} 1 4 5
Condition100%3/3
$deprecated_modules and exists $$deprecated_modules{$self->name}
!ll&&!rl&&r
131
MC/DC100%2/2
$deprecated_modules and exists $$deprecated_modules{$self->name}
$deprecated_modules exists $$deprecated_modules{$self->name}
Truth table100%3/3
A and B
A= $deprecated_modulesB= exists $$deprecated_modules{$self->name}
ABresult
0X0
100
111
105  
106 # on some perls, we'll get an 'uninitialized' warning when
107 # the $core_version is undef. So force to zero in that case
108 4 ▶ my $core_version = $core_modules->{ $self->name } || 0;
Condition50%1/2
$$core_modules{$self->name} || 0
l!l
40
MC/DC0%0/1
$$core_modules{$self->name} || 0
$$core_modules{$self->name}
Truth table50%1/2
A
A= $$core_modules{$self->name}
Aresult
11
00
109  
110 4 ▶ return 1 if $self->is_satisfied_by( $core_version );
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_satisfied_by($core_version) 3 1 4
111 1 return 0;
112 }
113  
114 #-------------------------------------------------------------------------------
115  
116  
117 4 ▶sub is_perl {
Subroutine is_perl: called CC=1 SCAR=0.0
Pod documented
118 4 my ($self) = @_;
119  
120 4 return $self->name eq 'perl';
121 }
122  
123 #-------------------------------------------------------------------------------
124  
125  
126 33 ▶sub is_satisfied_by {
Subroutine is_satisfied_by: called CC=1 SCAR=0.0
Pod documented
127 33 my ($self, $version) = @_;
128  
129 33 return $self->_vreq->accepts_module($self->name => $version);
130 }
131  
132 #-------------------------------------------------------------------------------
133  
134 0 ▶sub unversioned {
Subroutine unversioned: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my ($self) = @_;
136  
137 0 return (ref $self)->new(name => $self->name);
138 }
139  
140 #-------------------------------------------------------------------------------
141  
142  
143 77 ▶sub to_string {
Subroutine to_string: called CC=2 SCAR=6.9
Pod documented
144 77 my ($self) = @_;
145 77 ▶ my $format = $self->version =~ m/^ [=<>!\@] /x ? '%s%s' : '%s~%s';
Branch: 1 branch
BranchTrueFalseTotal
$self->version =~ /^ [=<>!\@] /x ? : 6 71 77
146 77 return sprintf $format, $self->name, $self->version;
147 }
148  
149 #------------------------------------------------------------------------------
150 # XXX Are we using this?
151  
152 0 ▶sub gte {
Subroutine gte: not called CC=3 SCAR=24.8
Pod undocumented
153 0 my ($self, $other, $flip) = @_;
154 0 ▶ return $self->is_satisfied_by($other) if not $flip;
Branch: 1 branch
BranchTrueFalseTotal
unless $flip 0 0 0
155 0 ▶ return $other->is_satisfied_by($self) if $flip;
Branch: 1 branch
BranchTrueFalseTotal
if $flip 0 0 0
156 }
157  
158 #------------------------------------------------------------------------------
159  
160 68 __PACKAGE__->meta->make_immutable;
161  
162 #------------------------------------------------------------------------------
163 68 1;
164  
165 __END__
« blib/lib/Pinto/Target.pm ↑ Summary blib/lib/Pinto/Store.pm »