line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Math::Depends; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Module::Math::Depends - Convenience object for manipulating module dependencies |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
This is a small convenience module created originally as part of |
12
|
|
|
|
|
|
|
L but released seperately, in the hope that people |
13
|
|
|
|
|
|
|
might find it useful in other contexts. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
26110
|
use 5.005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
83
|
|
20
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
21
|
2
|
|
|
2
|
|
22
|
use Carp (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
35
|
|
22
|
2
|
|
|
2
|
|
1938
|
use version (); |
|
2
|
|
|
|
|
5567
|
|
|
2
|
|
|
|
|
63
|
|
23
|
2
|
|
|
2
|
|
1831
|
use Params::Util qw{_CLASS _HASH _INSTANCE}; |
|
2
|
|
|
|
|
9379
|
|
|
2
|
|
|
|
|
231
|
|
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
18
|
use vars qw{$VERSION}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
88
|
|
26
|
|
|
|
|
|
|
BEGIN { |
27
|
2
|
|
|
2
|
|
940
|
$VERSION = '0.02'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
##################################################################### |
35
|
|
|
|
|
|
|
# Constructors |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $deps = Module::Math::Depends->new; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Creates a new, empty, dependency set. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
2
|
|
|
2
|
1
|
18
|
bless {}, $_[0]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 from_hash |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $deps = Module::Math::Depends->from_hash( \%modules ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Creates a new dependency set from a raw hashref of modules names |
54
|
|
|
|
|
|
|
and versions. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub from_hash { |
59
|
1
|
|
|
1
|
1
|
1342
|
my $self = shift()->new; |
60
|
1
|
50
|
|
|
|
9
|
my $hash = _HASH(shift) |
61
|
|
|
|
|
|
|
or Carp::croak("Did not provide a HASH reference"); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Add the deps |
64
|
1
|
|
|
|
|
3
|
foreach my $module ( keys %$hash ) { |
65
|
2
|
|
|
|
|
8
|
$self->add_module( $module => $hash->{$module} ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
$self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
##################################################################### |
76
|
|
|
|
|
|
|
# Main Methods |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 add_module |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$deps->add_module( 'My::Module' => '1.23' ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Adds a single module dependency to the set. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns true, or dies on error. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub add_module { |
89
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
90
|
2
|
50
|
|
|
|
58
|
my $name = _CLASS(shift) |
91
|
|
|
|
|
|
|
or Carp::croak("Invalid module name provided"); |
92
|
2
|
50
|
|
|
|
41
|
my $version = defined($_[0]) |
|
|
50
|
|
|
|
|
|
93
|
|
|
|
|
|
|
? ref($_[0]) |
94
|
|
|
|
|
|
|
? _INSTANCE(shift, 'version') |
95
|
|
|
|
|
|
|
: version->new(shift) |
96
|
|
|
|
|
|
|
: version->new(0); |
97
|
2
|
50
|
|
|
|
9
|
unless ( defined $version ) { |
98
|
0
|
|
|
|
|
0
|
Carp::croak("Invalid version provided"); |
99
|
|
|
|
|
|
|
} |
100
|
2
|
50
|
|
|
|
7
|
if ( $self->{$name} ) { |
101
|
0
|
0
|
|
|
|
0
|
if ( $version > $self->{$name} ) { |
102
|
0
|
|
|
|
|
0
|
$self->{$name} = $version; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} else { |
105
|
2
|
|
|
|
|
4
|
$self->{$name} = $version; |
106
|
|
|
|
|
|
|
} |
107
|
2
|
|
|
|
|
4
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 merge |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$my_deps->merge( $your_deps ); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The C method takes another dependency set and merges it into the |
115
|
|
|
|
|
|
|
current one, taking the highest version where both sets contain a module. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Returns true or dies on error. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub merge { |
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
123
|
0
|
0
|
|
|
|
|
my $from = _INSTANCE(shift, 'Module::Math::Depends') |
124
|
|
|
|
|
|
|
or Carp::croak("Did not provide a Module::Math::Depends object"); |
125
|
0
|
|
|
|
|
|
foreach my $name ( sort keys %$from ) { |
126
|
0
|
0
|
|
|
|
|
if ( $self->{$name} ) { |
127
|
0
|
0
|
|
|
|
|
if ( $from->{$name} > $self->{$name} ) { |
128
|
0
|
|
|
|
|
|
$self->{$name} = $from->{$name}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
|
$self->{$name} = $from->{$name}; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
return 1; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=pod |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 as_string |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
print $depends->as_string; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Converts the dependency set to a simple printable string. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub as_string { |
148
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
join '', map { "$_: $self->{$_}\n" } sort keys %$self; |
|
0
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=pod |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SUPPORT |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This module is stored in an Open Repository at the following address. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Write access to the repository is made available automatically to any |
163
|
|
|
|
|
|
|
published CPAN author, and to most other volunteers on request. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
If you are able to submit your bug report in the form of new (failing) |
166
|
|
|
|
|
|
|
unit tests, or can apply your fix directly instead of submitting a patch, |
167
|
|
|
|
|
|
|
you are B encouraged to do so as the author currently maintains |
168
|
|
|
|
|
|
|
over 100 modules and it can take some time to deal with non-Critcal bug |
169
|
|
|
|
|
|
|
reports or patches. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This will guarentee that your issue will be addressed in the next |
172
|
|
|
|
|
|
|
release of the module. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
If you cannot provide a direct test or fix, or don't have time to do so, |
175
|
|
|
|
|
|
|
then regular bug reports are still accepted and appreciated via the CPAN |
176
|
|
|
|
|
|
|
bug tracker. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
For other issues, for commercial enhancement or support, or to have your |
181
|
|
|
|
|
|
|
write access enabled for the repository, contact the author at the email |
182
|
|
|
|
|
|
|
address above. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHORS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 COPYRIGHT |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Copyright 2006 - 2008 Adam Kennedy. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This program is free software; you can redistribute |
193
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
The full text of the license can be found in the |
196
|
|
|
|
|
|
|
LICENSE file included with this module. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |