line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Flatten; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20109
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
20
|
use 5.008_005; |
|
1
|
|
|
|
|
3
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
497
|
use CPAN::Flatten::Distribution::Factory; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
4
|
use CPAN::Flatten::Distribution; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
3
|
use Module::CoreList; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
14
|
use version; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my ($class, %opt) = @_; |
14
|
0
|
|
0
|
|
|
|
my $target_perl = delete $opt{target_perl} || $]; |
15
|
0
|
0
|
|
|
|
|
$target_perl = "v$target_perl" if $target_perl =~ /^5\.[1-9]\d*$/; |
16
|
0
|
|
|
|
|
|
$target_perl = version->parse($target_perl)->numify; |
17
|
0
|
|
|
|
|
|
bless {target_perl => $target_perl, %opt}, $class; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
0
|
0
|
|
sub target_perl { shift->{target_perl} } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_core { |
22
|
0
|
|
|
0
|
0
|
|
my ($self, $package, $version) = @_; |
23
|
0
|
|
0
|
|
|
|
$version ||= 0; |
24
|
0
|
0
|
|
|
|
|
if ($package eq "perl") { |
25
|
0
|
0
|
|
|
|
|
if ($version > $self->target_perl) { |
26
|
0
|
|
|
|
|
|
my $err = "target perl version is only @{[$self->target_perl]}"; |
|
0
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return (undef, $err); |
28
|
|
|
|
|
|
|
} else { |
29
|
0
|
|
|
|
|
|
return (1, undef); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
0
|
0
|
|
|
|
|
if (exists $Module::CoreList::version{$self->target_perl}{$package}) { |
33
|
0
|
|
|
|
|
|
return (1, undef); |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
|
|
|
|
|
return (0, undef); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub info_progress { |
40
|
0
|
|
|
0
|
0
|
|
my ($self, $depth) = (shift, shift); |
41
|
0
|
0
|
|
|
|
|
return if $self->{quiet}; |
42
|
0
|
|
|
|
|
|
print STDERR " " x $depth, "@_"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
sub info_done { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
0
|
|
|
|
|
return if $self->{quiet}; |
47
|
0
|
|
|
|
|
|
print STDERR " -> @_\n"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub flatten { |
51
|
0
|
|
|
0
|
0
|
|
my ($self, $package, $version) = @_; |
52
|
0
|
|
|
|
|
|
my $distribution = CPAN::Flatten::Distribution->new; |
53
|
0
|
|
|
|
|
|
my $miss = +{}; |
54
|
0
|
|
|
|
|
|
$self->_flatten($distribution, $miss, $package, $version); |
55
|
0
|
|
|
|
|
|
my @miss = sort keys %$miss; |
56
|
0
|
0
|
|
|
|
|
return ($distribution, @miss ? \@miss : undef); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _flatten { |
60
|
0
|
|
|
0
|
|
|
my ($self, $distribution, $miss, $package, $version) = @_; |
61
|
0
|
0
|
|
|
|
|
return 0 if $miss->{$package}; |
62
|
0
|
|
0
|
|
|
|
$version ||= 0; |
63
|
0
|
|
|
|
|
|
my $already = $distribution->root->providing($package, $version); |
64
|
0
|
0
|
|
|
|
|
if ($already) { |
65
|
0
|
0
|
|
|
|
|
return 0 if $distribution->is_child($already); |
66
|
0
|
|
|
|
|
|
$distribution->add_child( $already->dummy ); |
67
|
0
|
|
|
|
|
|
return 1; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my ($is_core, $err) = $self->is_core($package, $version); |
71
|
0
|
0
|
|
|
|
|
if (!defined $is_core) { |
|
|
0
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$miss->{$package}++; |
73
|
0
|
|
|
|
|
|
$self->info_progress($distribution->depth, "$package ($version)"); |
74
|
0
|
|
|
|
|
|
$self->info_done("\e[31m$err\e[m"); |
75
|
0
|
|
|
|
|
|
return 0; |
76
|
|
|
|
|
|
|
} elsif ($is_core) { |
77
|
0
|
0
|
|
|
|
|
if ($self->{verbose}) { |
78
|
0
|
|
|
|
|
|
$self->info_progress($distribution->depth, "$package ($version)"); |
79
|
0
|
|
|
|
|
|
$self->info_done("core"); |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
return 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$self->info_progress($distribution->depth, "$package ($version)"); |
85
|
0
|
|
|
|
|
|
my ($found, $reason) = CPAN::Flatten::Distribution::Factory->from_pacakge($package, $version); |
86
|
0
|
0
|
|
|
|
|
if (!$found) { |
87
|
0
|
|
|
|
|
|
$miss->{$package}++; |
88
|
0
|
|
|
|
|
|
$self->info_done("\e[31m$reason\e[m"); |
89
|
0
|
|
|
|
|
|
return 0; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
$self->info_done("@{[$found->name]}"); |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$distribution->add_child($found); |
93
|
0
|
|
|
|
|
|
my $count = 0; |
94
|
0
|
|
|
|
|
|
for my $requirement (@{$found->requirements}) { |
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$count += $self->_flatten($found, $miss, $requirement->{package}, $requirement->{version}); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
return $count; # count == 0 means leaf |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |