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
|
1
|
|
|
1
|
|
43866
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use MooseX::MarkAsMethods ( autoclean => 1 ); |
7
|
|
|
|
|
|
|
use MooseX::Types::Moose qw(Str); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Try::Tiny; |
10
|
|
|
|
|
|
|
use Module::CoreList; |
11
|
|
|
|
|
|
|
use CPAN::Meta::Requirements; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Pinto::Types qw(Version); |
14
|
|
|
|
|
|
|
use Pinto::Util qw(throw trim_text); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use version; |
17
|
|
|
|
|
|
|
use overload ( '""' => 'to_string'); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.09995'; # 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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $args = {$self->name => $self->version}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $req = try { CPAN::Meta::Requirements->from_string_hash( $args) } |
79
|
|
|
|
|
|
|
catch { throw "Invalid package target ($self): $_" }; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->_set_vreq($req); |
82
|
|
|
|
|
|
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub is_core { |
89
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $pv = version->parse( $args{in} ) || version->parse($]); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# If it ain't in here, it ain't in the core |
98
|
|
|
|
|
|
|
my $core_modules = $Module::CoreList::version{ $pv->numify + 0 }; |
99
|
|
|
|
|
|
|
throw "Invalid perl version $pv" if not $core_modules; |
100
|
|
|
|
|
|
|
return 0 if not exists $core_modules->{ $self->name }; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# We treat deprecated modules as if they have already been removed |
103
|
|
|
|
|
|
|
my $deprecated_modules = $Module::CoreList::deprecated{ $pv->numify + 0 }; |
104
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $core_version = $core_modules->{ $self->name } || 0; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return 1 if $self->is_satisfied_by( $core_version ); |
111
|
|
|
|
|
|
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub is_perl { |
118
|
|
|
|
|
|
|
my ($self) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return $self->name eq 'perl'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub is_satisfied_by { |
127
|
|
|
|
|
|
|
my ($self, $version) = @_; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return $self->_vreq->accepts_module($self->name => $version); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub unversioned { |
135
|
|
|
|
|
|
|
my ($self) = @_; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return (ref $self)->new(name => $self->name); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub to_string { |
144
|
|
|
|
|
|
|
my ($self) = @_; |
145
|
|
|
|
|
|
|
my $format = $self->version =~ m/^ [=<>!\@] /x ? '%s%s' : '%s~%s'; |
146
|
|
|
|
|
|
|
return sprintf $format, $self->name, $self->version; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
150
|
|
|
|
|
|
|
# XXX Are we using this? |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub gte { |
153
|
|
|
|
|
|
|
my ($self, $other, $flip) = @_; |
154
|
|
|
|
|
|
|
return $self->is_satisfied_by($other) if not $flip; |
155
|
|
|
|
|
|
|
return $other->is_satisfied_by($self) if $flip; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
__END__ |