API/File/PackagesDetails.pm

filter: Statementstmt 91.4% 64 / 70 Branchbran 64.2% 9 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.2% 15 / 17 Podpod 100% 5 / 5 totaltotal 85.5% 95 / 111 CC 10 SCAR 12.7
CC
10
Cov
86%
parse
7.0
BUILDARGS
6.5
package
2.0
CRAP 3.5
« API/File/ModList.pm ↑ Summary API/File/MailRc.pm »
1 package CPAN::Index::API::File::PackagesDetails;
2  
3 1 our $VERSION = '0.008';
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Path::Class qw(file dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 with qw(
17 CPAN::Index::API::Role::Writable
18 CPAN::Index::API::Role::Readable
19 CPAN::Index::API::Role::Clonable
20 CPAN::Index::API::Role::HavingFilename
21 CPAN::Index::API::Role::HavingGeneratedBy
22 );
23  
24 1 has uri => (
25 is => 'ro',
26 isa => 'Str',
27 required => 1,
28 lazy_build => 1,
29 );
30  
31 1 has repo_uri => (
32 is => 'ro',
33 isa => 'Str',
34 );
35  
36 1 has description => (
37 is => 'ro',
38 isa => 'Str',
39 required => 1,
40 default => 'Package names found in directory $CPAN/authors/id/',
41 );
42  
43 1 has columns => (
44 is => 'ro',
45 isa => 'Str',
46 required => 1,
47 default => 'package name, version, path',
48 );
49  
50 1 has intended_for => (
51 is => 'ro',
52 isa => 'Str',
53 required => 1,
54 default => 'Automated fetch routines, namespace documentation.',
55 );
56  
57 has packages => (
58 is => 'bare',
59 isa => 'ArrayRef[HashRef]',
60 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
61 1 traits => ['Array'],
62 handles => {
63 package_count => 'count',
64 packages => 'elements',
65 add_package => 'push',
66 },
67 );
68  
69 5 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=4 SCAR=18.7
Pod documented
70 5 my ( $class, %args ) = @_;
71  
72 5 ▶ if ( $args{uri} or $args{repo_uri} )
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'uri'} or $args{'repo_uri'}) { } 5 0 5
elsif ($args{'repo_path'}) { } 0 0 0
Condition66%2/3
$args{"uri"} or $args{"repo_uri"}
l!l&&r!l&&!r
230
MC/DC0%0/2
$args{"uri"} or $args{"repo_uri"}
$args{"uri"} $args{"repo_uri"}
Truth table66%2/3
A or B
A= $args{"uri"}B= $args{"repo_uri"}
ABresult
1X1
011
000
73 {
74 5 return \%args;
75 }
76 elsif ($args{repo_path})
77 {
78 $args{repo_uri} = URI::file->new(
79 0 dir($args{repo_path})->absolute,
80 )->as_string;
81  
82 0 return \%args;
83 }
84 else
85 {
86 0 croak "Either 'uri', 'repo_uri' or 'repo_path' is required";
87 }
88 }
89  
90 3 ▶sub _build_uri {
Subroutine _build_uri: called CC=1 SCAR=0.0
91 3 my $self = shift;
92 3 my $uri = URI->new($self->repo_uri);
93 $uri->path_segments(
94 3 grep { $_ ne '' } $uri->path_segments,
95 file($self->default_location)->dir->dir_list,
96 file($self->default_location)->basename,
97 );
98 3 return $uri->as_string;
99 }
100  
101 sub package
102 0 ▶{
Subroutine package: not called CC=1 SCAR=6.9
Pod documented
103 0 my ($self, $name) = @_;
104 0 ▶ return first { $_->{name} eq $name } $self->packages;
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 }
106  
107 sub sorted_packages
108 3 ▶{
Subroutine sorted_packages: called CC=1 SCAR=0.0
Pod documented
109 3 my $self = shift;
110 3 return sort { $a->{name} cmp $b->{name} } $self->packages;
111 }
112  
113 2 ▶sub parse {
Subroutine parse: called CC=7 SCAR=19.5
Pod documented
114 2 my ( $self, $content ) = @_;
115  
116 2 my %map = (
117 'File' => 'file',
118 'URL' => 'uri',
119 'Description' => 'description',
120 'Columns' => 'columns',
121 'Intended-For' => 'intended_for',
122 'Written-By' => 'generated_by',
123 'Line-Count' => 'line_count',
124 'Last-Updated' => 'last_generated',
125 );
126  
127 2 my @lines = split "\n", $content;
128 2 my ( %args, @packages );
129  
130 2 ▶ while ( my $line = shift @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @lines) 16 2 18
131 16 ▶ last if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 16 16
132 16 ▶ next unless my ( $key, $value ) = $line =~ /^([^:]+):\s*(.*)/;
Branch: 1 branch
BranchTrueFalseTotal
unless () = $line =~ /^([^:]+):\s*(.*)/ 0 16 16
133 16 $args{$map{$key}} = $value;
134 }
135  
136 2 foreach my $line ( @lines ) {
137 4 my ( $name, $version, $distribution ) = split ' ', $line;
138  
139 # normalize missing version
140 4 ▶ undef $version if $version eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $version eq "undef" 1 3 4
141  
142 4 my $package = {
143 name => $name,
144 version => $version,
145 distribution => $distribution,
146 };
147 4 push @packages, $package;
148 }
149  
150 2 ▶ $args{packages} = \@packages if @packages;
Branch: 1 branch
BranchTrueFalseTotal
if @packages 1 1 2
151  
152 2 return %args;
153 }
154  
155 11 ▶sub default_location { 'modules/02packages.details.txt.gz' }
Subroutine default_location: called CC=1 SCAR=0.0
Pod documented
156  
157 1 __PACKAGE__->meta->make_immutable;
158  
159 =pod
160  
161 =encoding UTF-8
162  
163 =head1 NAME
164  
165 CPAN::Index::File::PackagesDetails - Interface to C<02packages.details.txt>.
166  
167 =head1 SYNOPSIS
168  
169 my $pckdetails = CPAN::Index::File::PackagesDetails->parse_from_repo_uri(
170 'http://cpan.perl.org'
171 );
172  
173 foreach my $package ($pckdetails->packages) {
174 ... # do something
175 }
176  
177 =head1 DESCRIPTION
178  
179 This is a class to read and write C<03modlist.data>.
180  
181 =head1 METHODS
182  
183 =head2 package
184  
185 First package in the list.
186  
187 =head2 packages
188  
189 List of hashrefs representing packages indexed in the file. Each hashref
190 has the following structure:
191  
192 =over
193  
194 =item name
195  
196 Package name, e.g. C<Foo::Bar>.
197  
198 =item version
199  
200 Package version, e.g. C<0.001>.
201  
202 =item distribution
203  
204 Distribution the package belongs to, e.g. C<Foo-Bar-0.001>.
205  
206 =back
207  
208 =head2 package_count
209  
210 Number of packages indexed in the file.
211  
212 =head2 filename
213  
214 Name of this file - defaults to C<02packages.details.txt.gz>;
215  
216 =head2 description
217  
218 Short description of the file.
219  
220 =head2 intended_for
221  
222 Target consumers of the file.
223  
224 =head2 uri
225  
226 Absolute URI pointing to the file location.
227  
228 =head2 parse
229  
230 Parses the file and returns its representation as a data structure.
231  
232 =head2 default_location
233  
234 Default file location - C<modules/02packages.details.txt.gz>.
235  
236 =head2 sorted_packages
237  
238 The list of packages sorted by name.
239  
240 =head1 METHODS FROM ROLES
241  
242 =over
243  
244 =item <CPAN::Index::API::Role::Readable/read_from_string>
245  
246 =item <CPAN::Index::API::Role::Readable/read_from_file>
247  
248 =item <CPAN::Index::API::Role::Readable/read_from_tarball>
249  
250 =item <CPAN::Index::API::Role::Readable/read_from_repo_path>
251  
252 =item <CPAN::Index::API::Role::Readable/read_from_repo_uri>
253  
254 =item L<CPAN::Index::API::Role::Writable/tarball_is_default>
255  
256 =item L<CPAN::Index::API::Role::Writable/repo_path>
257  
258 =item L<CPAN::Index::API::Role::Writable/template>
259  
260 =item L<CPAN::Index::API::Role::Writable/content>
261  
262 =item L<CPAN::Index::API::Role::Writable/write_to_file>
263  
264 =item L<CPAN::Index::API::Role::Writable/write_to_tarball>
265  
266 =item L<CPAN::Index::API::Role::Clonable/clone>
267  
268 =item L<CPAN::Index::API::Role::HavingFilename/filename>
269  
270 =item L<CPAN::Index::API::Role::HavingGeneratedBy/generated_by>
271  
272 =item L<CPAN::Index::API::Role::HavingGeneratedBy/last_generated>
273  
274 =back
275  
276 =cut
277  
278 __DATA__
« API/File/ModList.pm ↑ Summary API/File/MailRc.pm »