line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
6
|
|
|
6
|
|
107
|
use 5.006; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
275
|
|
2
|
6
|
|
|
6
|
|
36
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
195
|
|
3
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
307
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Metabase::Resource::cpan::distfile; |
6
|
|
|
|
|
|
|
our $VERSION = '0.024'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
28
|
use Carp (); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
117
|
|
9
|
6
|
|
|
6
|
|
5547
|
use CPAN::DistnameInfo (); |
|
6
|
|
|
|
|
6781
|
|
|
6
|
|
|
|
|
130
|
|
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
44
|
use Metabase::Resource::cpan; |
|
6
|
|
|
|
|
72
|
|
|
6
|
|
|
|
|
2545
|
|
12
|
|
|
|
|
|
|
our @ISA = qw/Metabase::Resource::cpan/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _metadata_types { |
15
|
|
|
|
|
|
|
return { |
16
|
1
|
|
|
1
|
|
15
|
cpan_id => '//str', |
17
|
|
|
|
|
|
|
dist_file => '//str', |
18
|
|
|
|
|
|
|
dist_name => '//str', |
19
|
|
|
|
|
|
|
dist_version => '//str', |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _init { |
24
|
34
|
|
|
34
|
|
51
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# determine subtype |
27
|
34
|
|
|
|
|
1416
|
my ($string) = $self =~ m{\Acpan:///distfile/(.+)\z}; |
28
|
34
|
50
|
33
|
|
|
328
|
Carp::confess("could not determine distfile from '$self'\n") |
29
|
|
|
|
|
|
|
unless defined $string && length $string; |
30
|
|
|
|
|
|
|
|
31
|
34
|
|
|
|
|
84
|
my $data = $self->_validate_distfile($string); |
32
|
34
|
|
|
|
|
110
|
for my $k ( keys %$data ) { |
33
|
136
|
|
|
|
|
976
|
$self->_add( $k => $data->{$k} ); |
34
|
|
|
|
|
|
|
} |
35
|
34
|
|
|
|
|
142
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# distfile validates during _init, really |
39
|
34
|
|
|
34
|
1
|
60
|
sub validate { 1 } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# XXX should really validate AUTHOR/DISTNAME-DISTVERSION.SUFFIX |
42
|
|
|
|
|
|
|
# -- dagolden, 2010-01-27 |
43
|
|
|
|
|
|
|
# |
44
|
|
|
|
|
|
|
# my $suffix = qr{\.(?:tar\.(?:bz2|gz|Z)|t(?:gz|bz)|zip)}; |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# for now, we'll use CPAN::DistnameInfo; |
47
|
|
|
|
|
|
|
# |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# map DistnameInfo calls to our names |
50
|
|
|
|
|
|
|
my %distfile_map = ( |
51
|
|
|
|
|
|
|
cpanid => 'cpan_id', |
52
|
|
|
|
|
|
|
dist => 'dist_name', |
53
|
|
|
|
|
|
|
version => 'dist_version', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _validate_distfile { |
57
|
34
|
|
|
34
|
|
54
|
my ( $self, $string ) = @_; |
58
|
34
|
|
|
|
|
69
|
my $two = substr( $string, 0, 2 ); |
59
|
34
|
|
|
|
|
53
|
my $one = substr( $two, 0, 1 ); |
60
|
34
|
|
|
|
|
90
|
my $path = "authors/id/$one/$two/$string"; |
61
|
34
|
|
|
|
|
50
|
my $d = eval { CPAN::DistnameInfo->new($path) }; |
|
34
|
|
|
|
|
131
|
|
62
|
34
|
50
|
|
|
|
2505
|
my $bad = defined $d ? 0 : 1; |
63
|
|
|
|
|
|
|
|
64
|
34
|
|
|
|
|
86
|
my $cache = { dist_file => $string }; |
65
|
|
|
|
|
|
|
|
66
|
34
|
50
|
|
|
|
122
|
for my $k ( $bad ? () : ( keys %distfile_map ) ) { |
67
|
102
|
|
|
|
|
407
|
my $value = $d->$k; |
68
|
102
|
50
|
0
|
|
|
485
|
defined $value or $bad++ and last; |
69
|
102
|
|
|
|
|
358
|
$cache->{ $distfile_map{$k} } = $value; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
34
|
50
|
|
|
|
101
|
if ($bad) { |
73
|
0
|
|
|
|
|
0
|
Carp::confess("'$string' can't be parsed as a CPAN distfile"); |
74
|
|
|
|
|
|
|
} |
75
|
34
|
|
|
|
|
169
|
return $cache; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# ABSTRACT: class for Metabase resources |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |