line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Access::AdHoc::Util; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
20298
|
use 5.008; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
248
|
|
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
33
|
use strict; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
225
|
|
6
|
7
|
|
|
7
|
|
42
|
use warnings; |
|
7
|
|
|
|
|
32
|
|
|
7
|
|
|
|
|
168
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
33
|
use base qw{ Exporter }; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
829
|
|
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
5743
|
use LWP::MediaTypes (); |
|
7
|
|
|
|
|
103222
|
|
|
7
|
|
|
|
|
7079
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
13
|
|
|
|
|
|
|
__attr __cache __expand_distribution_path __guess_media_type |
14
|
|
|
|
|
|
|
__load __whinge __wail __weep |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
18
|
|
|
|
|
|
|
all => [ @EXPORT_OK ], |
19
|
|
|
|
|
|
|
carp => [ qw{ __whinge __wail __weep } ], |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.000_18'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub __attr { |
25
|
435
|
|
|
435
|
|
652
|
my ( $self ) = @_; |
26
|
435
|
|
|
|
|
930
|
my $name_space = caller; |
27
|
435
|
|
100
|
|
|
3261
|
return ( $self->{$name_space} ||= {} ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub __cache { |
31
|
18
|
|
|
18
|
|
35
|
my ( $self ) = @_; |
32
|
18
|
|
|
|
|
50
|
my $name_space = caller; |
33
|
18
|
|
100
|
|
|
151
|
return ( $self->{'.cache'}{$name_space} ||= {} ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub __expand_distribution_path { |
37
|
15
|
|
|
15
|
|
36
|
my ( $path ) = @_; |
38
|
15
|
100
|
|
|
|
103
|
$path =~ m{ \A ( [^/] ) / ( \1 [^/] ) / ( \2 [^/]* ) }smx |
39
|
|
|
|
|
|
|
and return $path; |
40
|
8
|
50
|
|
|
|
31
|
$path =~ m< \A ( [^/]{2} ) / ( \1 [^/]* ) >smx |
41
|
|
|
|
|
|
|
and return join '/', substr( $1, 0, 1 ), $path; |
42
|
8
|
50
|
|
|
|
50
|
$path =~ m< \A ( [^/]+ ) >smx |
43
|
|
|
|
|
|
|
or __wail( "Invalid distribution path '$path'" ); |
44
|
8
|
|
|
|
|
59
|
return join '/', substr( $1, 0, 1 ), |
45
|
|
|
|
|
|
|
substr( $1, 0, 2 ), $path; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my %expand_ending = ( |
51
|
|
|
|
|
|
|
tbz => 'tar.bz2', |
52
|
|
|
|
|
|
|
tgz => 'tar.gz', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub __guess_media_type { |
56
|
53
|
|
|
53
|
|
11296
|
my ( $resp, $path ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
53
|
50
|
|
|
|
191
|
if ( defined $path ) { |
59
|
53
|
|
|
|
|
213
|
$resp->header( 'Content-Location' => $path ); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
0
|
|
|
|
0
|
defined( $path = $resp->header( 'Content-Location' ) ) |
62
|
|
|
|
|
|
|
or __wail( |
63
|
|
|
|
|
|
|
'No path provided, and none in Content-Location' ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# LWP::MediaTypes needs help with some paths. |
67
|
53
|
|
|
|
|
2941
|
$path =~ s{ (?<= [.] ) ( [^.]+ ) \z } |
68
|
49
|
100
|
|
|
|
319
|
{ $expand_ending{$1} || $1 }smxie; |
69
|
|
|
|
|
|
|
|
70
|
53
|
|
|
|
|
203
|
LWP::MediaTypes::guess_media_type( $path, $resp ); |
71
|
|
|
|
|
|
|
|
72
|
53
|
|
|
|
|
6485
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub __load { |
78
|
17
|
|
|
17
|
|
503
|
my ( @args ) = @_; |
79
|
17
|
|
|
|
|
65
|
foreach my $module ( @args ) { |
80
|
|
|
|
|
|
|
|
81
|
17
|
100
|
|
|
|
142
|
$module =~ m< \A |
82
|
|
|
|
|
|
|
[[:alpha:]_] \w* |
83
|
|
|
|
|
|
|
(?: :: [[:alpha:]_] \w* )* \z |
84
|
|
|
|
|
|
|
>smx |
85
|
|
|
|
|
|
|
or __wail( "Malformed module name '$module'" ); |
86
|
|
|
|
|
|
|
|
87
|
16
|
|
|
|
|
65
|
( my $fn = $module ) =~ s{ :: }{/}smxg; |
88
|
16
|
|
|
|
|
32
|
$fn .= '.pm'; |
89
|
16
|
|
|
|
|
6126
|
require $fn; |
90
|
|
|
|
|
|
|
} |
91
|
16
|
|
|
|
|
56
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
our @CARP_NOT = qw{ |
95
|
|
|
|
|
|
|
CPAN::Access::AdHoc |
96
|
|
|
|
|
|
|
CPAN::Access::AdHoc::Archive |
97
|
|
|
|
|
|
|
CPAN::Access::AdHoc::Archive::Null |
98
|
|
|
|
|
|
|
CPAN::Access::AdHoc::Archive::Tar |
99
|
|
|
|
|
|
|
CPAN::Access::AdHoc::Archive::Zip |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub __whinge { |
104
|
1
|
|
|
1
|
|
418
|
my @args = @_; |
105
|
1
|
|
|
|
|
9
|
require Carp; |
106
|
1
|
|
|
|
|
248
|
Carp::carp( @args ); |
107
|
1
|
|
|
|
|
6
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub __wail { |
111
|
15
|
|
|
15
|
|
912
|
my @args = @_; |
112
|
15
|
|
|
|
|
112
|
require Carp; |
113
|
15
|
|
|
|
|
2340
|
Carp::croak( @args ); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub __weep { |
117
|
7
|
|
|
7
|
|
528
|
my @args = @_; |
118
|
7
|
|
|
|
|
31
|
require Carp; |
119
|
7
|
|
|
|
|
1110
|
Carp::confess( 'Programming Error - ', @args ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |