line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Index::API::Role::Readable; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$CPAN::Index::API::Role::Readable::VERSION = '0.007'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Reads index files |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
2812
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
129
|
|
9
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
110
|
|
10
|
3
|
|
|
3
|
|
22
|
use File::Slurp qw(read_file); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
205
|
|
11
|
3
|
|
|
3
|
|
19
|
use File::Temp qw(tempfile); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
225
|
|
12
|
3
|
|
|
3
|
|
17
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
160
|
|
13
|
3
|
|
|
3
|
|
17
|
use Path::Class qw(file); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
168
|
|
14
|
3
|
|
|
3
|
|
18
|
use Carp qw(croak); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
132
|
|
15
|
3
|
|
|
3
|
|
2647
|
use LWP::Simple; |
|
3
|
|
|
|
|
237918
|
|
|
3
|
|
|
|
|
60
|
|
16
|
3
|
|
|
3
|
|
1548
|
use Compress::Zlib qw(gzopen Z_STREAM_END), '$gzerrno'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
340
|
|
17
|
3
|
|
|
3
|
|
16
|
use Moose::Role; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
61
|
|
18
|
3
|
|
|
3
|
|
17676
|
use namespace::clean -except => 'meta'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
39
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
requires 'parse'; |
21
|
|
|
|
|
|
|
requires 'default_location'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub read_from_string |
24
|
|
|
|
|
|
|
{ |
25
|
5
|
|
|
5
|
1
|
3195
|
my ($self, $content, %args) = @_; |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
28
|
%args = ( $self->parse($content), %args ); |
28
|
|
|
|
|
|
|
|
29
|
5
|
50
|
|
|
|
54
|
if ( blessed $self ) |
30
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
|
|
0
|
foreach my $key ( keys %args ) |
32
|
|
|
|
|
|
|
{ |
33
|
0
|
|
|
|
|
0
|
$self->$key($args{$key}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else |
37
|
|
|
|
|
|
|
{ |
38
|
5
|
|
|
|
|
212
|
return $self->new(%args); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub read_from_file { |
43
|
0
|
|
|
0
|
1
|
|
my ($self, $file, %args) = @_; |
44
|
0
|
|
|
|
|
|
my $content = read_file($file); |
45
|
0
|
|
|
|
|
|
return $self->read_from_string($content, %args); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub read_from_tarball |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
1
|
|
my ($self, $tarball, %args) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
my $gz = gzopen($tarball, 'rb') or croak "Cannot open $tarball: $gzerrno"; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my ($buffer, $content); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$content .= $buffer while $gz->gzread($buffer) > 0 ; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
croak "Error reading from $tarball: $gzerrno" . ($gzerrno+0) . "\n" |
59
|
|
|
|
|
|
|
if $gzerrno != Z_STREAM_END; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$gz->gzclose and croak "Error closing $tarball"; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->read_from_string($content, %args); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub read_from_repo_path |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
1
|
|
my ($self, $repo_path, %args) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$args{repo_path} = $repo_path; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
return $self->read_from_tarball( |
73
|
|
|
|
|
|
|
file( $repo_path, $self->default_location )->stringify, %args |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub read_from_repo_uri |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $repo_uri, %args) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$args{repo_uri} = $repo_uri; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $uri = URI->new( $repo_uri ); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$uri->path_segments( |
86
|
|
|
|
|
|
|
$uri->path_segments, |
87
|
|
|
|
|
|
|
file($self->default_location)->dir->dir_list, |
88
|
|
|
|
|
|
|
file($self->default_location)->basename, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $uri_as_string = $uri->as_string; |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
my $content = LWP::Simple::get( $uri_as_string ) |
94
|
|
|
|
|
|
|
or croak "Failed to fetch $uri_as_string"; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my ( $fh, $filename ) = tempfile; |
97
|
0
|
0
|
|
|
|
|
print $fh LWP::Simple::get( $uri->as_string ) or croak $!; |
98
|
0
|
0
|
|
|
|
|
close $fh or croak $!; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self->read_from_tarball( $filename, %args ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |
107
|
|
|
|
|
|
|
=pod |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
CPAN::Index::API::Role::Readable - Reads index files |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 VERSION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
version 0.007 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This role provides a collection of utility constructors for CPAN index file |
120
|
|
|
|
|
|
|
objects. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 REQUIRES |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 default_location |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Class method that returns a string specifying the path to the default location |
127
|
|
|
|
|
|
|
of this file relative to the repository root. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 parse |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
This class method (generally invoked as part of the construction phase) |
132
|
|
|
|
|
|
|
should accept a string containing an index file, and return a list of |
133
|
|
|
|
|
|
|
key/value pairs suitable for passing to the constructor of the consuming class. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 PROVIDES |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 read_from_string |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Construct a new index file object by reading the file contents from a string. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 read_from_file |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Construct a new index file object by reading the file contents from a filename. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 read_from_tarball |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Construct a new index file object by reading the file contents from a tarball. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 read_from_repo_path |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Construct a new index file object by locating and parsing a file in a local |
152
|
|
|
|
|
|
|
repository. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 read_from_repo_uri |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Construct a new index file object by locating and parsing a file in a remote |
157
|
|
|
|
|
|
|
repository. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 AUTHOR |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Peter Shangov <pshangov@yahoo.com> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Venda, Inc.. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
168
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|