line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Specifies a package by name and version |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Pinto::Target::Package; |
4
|
|
|
|
|
|
|
|
5
|
56
|
|
|
56
|
|
52787
|
use Moose; |
|
56
|
|
|
|
|
378476
|
|
|
56
|
|
|
|
|
437
|
|
6
|
56
|
|
|
56
|
|
348995
|
use MooseX::MarkAsMethods ( autoclean => 1 ); |
|
56
|
|
|
|
|
19928
|
|
|
56
|
|
|
|
|
532
|
|
7
|
56
|
|
|
56
|
|
185712
|
use MooseX::Types::Moose qw(Str); |
|
56
|
|
|
|
|
47790
|
|
|
56
|
|
|
|
|
651
|
|
8
|
|
|
|
|
|
|
|
9
|
56
|
|
|
56
|
|
256967
|
use Try::Tiny; |
|
56
|
|
|
|
|
140
|
|
|
56
|
|
|
|
|
3783
|
|
10
|
56
|
|
|
56
|
|
2601
|
use Module::CoreList; |
|
56
|
|
|
|
|
75783
|
|
|
56
|
|
|
|
|
553
|
|
11
|
56
|
|
|
56
|
|
19946
|
use CPAN::Meta::Requirements; |
|
56
|
|
|
|
|
137221
|
|
|
56
|
|
|
|
|
1765
|
|
12
|
|
|
|
|
|
|
|
13
|
56
|
|
|
56
|
|
858
|
use Pinto::Types qw(Version); |
|
56
|
|
|
|
|
129
|
|
|
56
|
|
|
|
|
514
|
|
14
|
56
|
|
|
56
|
|
329921
|
use Pinto::Util qw(throw trim_text); |
|
56
|
|
|
|
|
153
|
|
|
56
|
|
|
|
|
3572
|
|
15
|
|
|
|
|
|
|
|
16
|
56
|
|
|
56
|
|
653
|
use version; |
|
56
|
|
|
|
|
135
|
|
|
56
|
|
|
|
|
453
|
|
17
|
56
|
|
|
56
|
|
4751
|
use overload ( '""' => 'to_string'); |
|
56
|
|
|
|
|
127
|
|
|
56
|
|
|
|
|
504
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.14'; # VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has name => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => Str, |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has version => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => Str | Version, |
34
|
|
|
|
|
|
|
default => '0', |
35
|
|
|
|
|
|
|
coerce => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has _vreq => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => 'CPAN::Meta::Requirements', |
41
|
|
|
|
|
|
|
writer => '_set_vreq', |
42
|
|
|
|
|
|
|
init_arg => undef, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
around BUILDARGS => sub { |
48
|
|
|
|
|
|
|
my $orig = shift; |
49
|
|
|
|
|
|
|
my $class = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my @args = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if ( @args == 1 and not ref $args[0] ) { |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
throw "Invalid package specification: $_[0]" |
56
|
|
|
|
|
|
|
unless $_[0] =~ m{^ ([A-Z0-9_:]+) (?:~)? (.*)}ix; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my ($name, $version) = ($1, $2); |
59
|
|
|
|
|
|
|
$version =~ s/^\@/==/; # Allow "@" as a synonym for "==" |
60
|
|
|
|
|
|
|
@args = ( name => $name, version => trim_text($version) || 0 ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return $class->$orig(@args); |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub BUILD { |
69
|
170
|
|
|
170
|
0
|
383
|
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
|
170
|
|
|
|
|
4484
|
my $args = {$self->name => $self->version}; |
77
|
|
|
|
|
|
|
|
78
|
170
|
|
|
170
|
|
9394
|
my $req = try { CPAN::Meta::Requirements->from_string_hash( $args) } |
79
|
170
|
|
|
0
|
|
1686
|
catch { throw "Invalid package target ($self): $_" }; |
|
0
|
|
|
|
|
0
|
|
80
|
|
|
|
|
|
|
|
81
|
170
|
|
|
|
|
41699
|
$self->_set_vreq($req); |
82
|
170
|
|
|
|
|
4015
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub is_core { |
89
|
105
|
|
|
105
|
1
|
1235
|
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
|
105
|
|
66
|
|
|
2301
|
my $pv = version->parse( $args{in} ) || version->parse($]); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# If it ain't in here, it ain't in the core |
98
|
105
|
|
|
|
|
2503
|
my $core_modules = $Module::CoreList::version{ $pv->numify + 0 }; |
99
|
105
|
50
|
|
|
|
369
|
throw "Invalid perl version $pv" if not $core_modules; |
100
|
105
|
100
|
|
|
|
2909
|
return 0 if not exists $core_modules->{ $self->name }; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# We treat deprecated modules as if they have already been removed |
103
|
12
|
|
|
|
|
125
|
my $deprecated_modules = $Module::CoreList::deprecated{ $pv->numify + 0 }; |
104
|
12
|
100
|
100
|
|
|
230
|
return 0 if $deprecated_modules && exists $deprecated_modules->{ $self->name }; |
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
|
11
|
|
50
|
|
|
265
|
my $core_version = $core_modules->{ $self->name } || 0; |
109
|
|
|
|
|
|
|
|
110
|
11
|
100
|
|
|
|
48
|
return 1 if $self->is_satisfied_by( $core_version ); |
111
|
2
|
|
|
|
|
120
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_perl { |
118
|
64
|
|
|
64
|
1
|
835
|
my ($self) = @_; |
119
|
|
|
|
|
|
|
|
120
|
64
|
|
|
|
|
1511
|
return $self->name eq 'perl'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub is_satisfied_by { |
127
|
147
|
|
|
147
|
1
|
3547
|
my ($self, $version) = @_; |
128
|
|
|
|
|
|
|
|
129
|
147
|
|
|
|
|
3795
|
return $self->_vreq->accepts_module($self->name => $version); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub unversioned { |
135
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
0
|
return (ref $self)->new(name => $self->name); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub to_string { |
144
|
1065
|
|
|
1065
|
1
|
5675
|
my ($self) = @_; |
145
|
1065
|
100
|
|
|
|
25472
|
my $format = $self->version =~ m/^ [=<>!\@] /x ? '%s%s' : '%s~%s'; |
146
|
1065
|
|
|
|
|
24462
|
return sprintf $format, $self->name, $self->version; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
150
|
|
|
|
|
|
|
# XXX Are we using this? |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub gte { |
153
|
0
|
|
|
0
|
0
|
|
my ($self, $other, $flip) = @_; |
154
|
0
|
0
|
|
|
|
|
return $self->is_satisfied_by($other) if not $flip; |
155
|
0
|
0
|
|
|
|
|
return $other->is_satisfied_by($self) if $flip; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=pod |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=encoding UTF-8 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=for :stopwords Jeffrey Ryan Thalhammer |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 NAME |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Pinto::Target::Package - Specifies a package by name and version |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 VERSION |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
version 0.14 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 METHODS |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 is_core |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 is_core(in => $version) |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Returns true if this Target is satisfied by the perl core as-of a particular |
188
|
|
|
|
|
|
|
version. If the version is not specified, it defaults to whatever version you |
189
|
|
|
|
|
|
|
are using now. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 is_perl() |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns true if this Target is a perl version of perl itself. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 is_satisfied_by($version) |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns true if this Target is satisfied by version C<$version> of the package. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 to_string() |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Serializes this Target to its string form. This method is called whenever the |
202
|
|
|
|
|
|
|
Target is evaluated in string context. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 AUTHOR |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@stratopan.com> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
213
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |