line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::License::Report::CPANPLUS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
93
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
1610
|
use CPANPLUS::Backend; |
|
1
|
|
|
|
|
809448
|
|
|
1
|
|
|
|
|
162
|
|
6
|
1
|
|
|
1
|
|
1369
|
use Module::License::Report::CPANPLUSModule; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1043
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Module::License::Report::CPANPLUS - Interface to CPANPLUS::Backend |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 LICENSE |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Copyright 2005 Clotho Advanced Media, Inc., |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
19
|
|
|
|
|
|
|
under the same terms as Perl itself. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Module::License::Report::CPANPLUS; |
24
|
|
|
|
|
|
|
my $cp = Module::License::Report::CPANPLUS->new(); |
25
|
|
|
|
|
|
|
my $module = $cp->get_module('Foo::Bar'); |
26
|
|
|
|
|
|
|
my $license = $module->license(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This is an abstraction of the CPANPLUS API for use by |
31
|
|
|
|
|
|
|
Module::License::Report. It's unlikely that you want to use this |
32
|
|
|
|
|
|
|
directly. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 FUNCTIONS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item $pkg->new() |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item $pkg->new({key =E value, ...}) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create a new instance. Supported options are C and C. |
43
|
|
|
|
|
|
|
C is an instantiated CPANPLUS::Backend instance. If you omit |
44
|
|
|
|
|
|
|
that (which is recommended), one will be created for you. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
1
|
1
|
63
|
my $pkg = shift; |
51
|
1
|
|
50
|
|
|
6
|
my $opts_hash = shift || {}; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
9
|
my $self = bless { |
54
|
|
|
|
|
|
|
%$opts_hash, |
55
|
|
|
|
|
|
|
modcache => {}, |
56
|
|
|
|
|
|
|
}, $pkg; |
57
|
1
|
50
|
|
|
|
16
|
if (!$self->{cb}) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
0
|
$self->{cb} = CPANPLUS::Backend->new(); |
60
|
|
|
|
|
|
|
} |
61
|
1
|
|
|
|
|
7
|
$self->{cb}->configure_object->set_conf(verbose => $self->{verbose}); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
17
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item $self->set_host($url) |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Changes the mirror site that CPANPLUS uses to download packages. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub set_host |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
75
|
0
|
|
|
|
|
0
|
my $host = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
0
|
|
|
0
|
if ($host && $host eq 'default') |
|
|
0
|
0
|
|
|
|
|
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
# noop |
80
|
0
|
|
|
|
|
0
|
return 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ($host && $host =~ m{ \A (\w+)://([\w\.\-]+)(/.*) \z }xms) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
0
|
$self->{cb}->configure_object->set_conf('hosts', [{ |
85
|
|
|
|
|
|
|
scheme => $1, |
86
|
|
|
|
|
|
|
host => $2, |
87
|
|
|
|
|
|
|
path => $3, |
88
|
|
|
|
|
|
|
}]); |
89
|
0
|
|
|
|
|
0
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
0
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item $self->get_module($module_name) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns a Module::License::Report::CPANPLUSModule instance. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The argument can be either a module name like C or a |
102
|
|
|
|
|
|
|
distribution name like C. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub get_module |
107
|
|
|
|
|
|
|
{ |
108
|
1
|
|
|
1
|
1
|
909
|
my $self = shift; |
109
|
1
|
|
|
|
|
3
|
my $modname = shift; |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
2
|
my $cache = $self->{modcache}; |
112
|
1
|
|
|
|
|
4
|
my $key = lc $modname; |
113
|
1
|
50
|
|
|
|
4
|
if (!$cache->{$key}) |
114
|
|
|
|
|
|
|
{ |
115
|
1
|
|
|
|
|
14
|
my $mod = Module::License::Report::CPANPLUSModule->new($self, $modname); |
116
|
1
|
|
|
|
|
5
|
$cache->{$key} = $mod; |
117
|
1
|
50
|
|
|
|
6
|
if ($mod) |
118
|
|
|
|
|
|
|
{ |
119
|
|
|
|
|
|
|
# Prefill alternate name, if any, in the cache |
120
|
1
|
|
|
|
|
5
|
$cache->{lc $mod->package_name} = $mod; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
0
|
|
|
|
|
0
|
return $cache->{$key}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _module_by_name |
127
|
|
|
|
|
|
|
{ |
128
|
|
|
|
|
|
|
# Returns CPANPLUS module (internal only) |
129
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
130
|
1
|
|
|
|
|
1
|
my $modname = shift; |
131
|
|
|
|
|
|
|
|
132
|
1
|
50
|
|
|
|
11
|
if ($modname =~ m/\A \w+ (?: ::\w+)* \z /xms) |
133
|
|
|
|
|
|
|
{ |
134
|
1
|
|
|
|
|
10
|
return $self->{cb}->module_tree($modname); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
else |
137
|
|
|
|
|
|
|
{ |
138
|
|
|
|
|
|
|
# E.g. Foo-Bar-0.12.03_01.tar.gz |
139
|
0
|
|
|
|
|
|
my $re = qr/\A \Q$modname\E - \d[\d\._]*\.(?:tar\.gz|zip|tgz) \z /ixms; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# get matching module with the latest version number |
142
|
|
|
|
|
|
|
# use the Schwarzian Transform |
143
|
0
|
|
|
|
|
|
my @mods = map {$_->[0]} |
|
0
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
sort {$b->[1] cmp $a->[1]} |
145
|
0
|
|
|
|
|
|
map {[$_, $_->package_version]} |
146
|
|
|
|
|
|
|
$self->{cb}->search(type => 'package', allow => [$re]); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#print 'Search yielded '.$mods[0]->name." for package $modname\n" if ($mods[0] && $self->{verbose}); |
149
|
0
|
|
|
|
|
|
return $mods[0]; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
__END__ |