API/File/ModList.pm

filter: Statementstmt 98.1% 52 / 53 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 93.3% 70 / 75 CC 8 SCAR 14.8
CC
8
Cov
92%
parse
8.2
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
« API/Role/Writable.pm ↑ Summary API/File/PackagesDetails.pm »
1 package CPAN::Index::API::File::ModList;
2 {
3 2 $CPAN::Index::API::File::ModList::VERSION = '0.007';
4 }
5  
6 # ABSTRACT: Interface to 03modlist.data
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp qw(carp croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Path::Class qw(file);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 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 2 has description => (
25 is => 'ro',
26 isa => 'Str',
27 required => 1,
28 default => 'Package names found in directory $CPAN/authors/id/',
29 );
30  
31 has modules => (
32 is => 'bare',
33 isa => 'ArrayRef',
34 2 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 2 traits => ['Array'],
36 handles => {
37 module_count => 'count',
38 modules => 'elements',
39 },
40 );
41  
42 # lots of code from Parse::CPAN::Modlist here
43 sub parse {
44 2 ▶ my ( $self, $content ) = @_;
Subroutine parse: called CC=8 SCAR=21.0
Pod documented
45  
46 ### get rid of the comments and the code ###
47 ### need a smarter parser, some people have this in their dslip info:
48 # [
49 # 'Statistics::LTU',
50 # 'R',
51 # 'd',
52 # 'p',
53 # 'O',
54 # '?',
55 # 'Implements Linear Threshold Units',
56 # ...skipping...
57 # "\x{c4}dd \x{fc}ml\x{e4}\x{fc}ts t\x{f6} \x{eb}v\x{eb}r\x{ff}th\x{ef}ng!",
58 # 'BENNIE',
59 # '11'
60 # ],
61 ### also, older versions say:
62 ### $cols = [....]
63 ### and newer versions say:
64 ### $CPANPLUS::Modulelist::cols = [...]
65 2 $content =~ s/.+}\s+(\$(?:CPAN::Modulelist::)?cols)/$1/s;
66  
67 ### split '$cols' and '$data' into 2 variables ###
68 2 my ($ds_one, $ds_two) = split ';', $content, 2;
69  
70 ### eval them into existance ###
71 2 my ($columns, $data, @modules, %args );
72  
73 2 $columns = eval $ds_one;
74 2 ▶ croak "Error in eval of 03modlist.data source files: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
75  
76 2 $data = eval $ds_two;
77 2 ▶ croak "Error in eval of 03modlist.data source files: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
78  
79 2 my %map = (
80 modid => 'name',
81 statd => 'development_stage',
82 stats => 'support_level',
83 statl => 'language_used',
84 stati => 'interface_style',
85 statp => 'public_license',
86 userid => 'authorid',
87 chapterid => 'chapterid',
88 description => 'description',
89 );
90  
91 2 ▶ if ( my @unknown_columns = grep { ! $map{$_} } @$columns ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@unknown_columns) = grep({not $map{$_};} @$columns)) 0 2 2
92 0 carp "Found unknown columns in 03modlist.data: "
93 . join ', ', @unknown_columns;
94 }
95  
96 2 foreach my $entry ( @$data ) {
97 3 my %module;
98  
99 3 @module{@map{@$columns}} = @$entry;
100 3 $module{chapterid} = int($module{chapterid});
101  
102 3 my @dslip = qw(
103 development_stage
104 support_level
105 language_used
106 interface_style
107 public_license
108 );
109  
110 3 undef $module{$_} for grep { $module{$_} eq '?' } @dslip;
111  
112 3 ▶ $module{dslip} = join '', map { defined $_ ? $_ : '?' } @dslip;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 15 0 15
113  
114 3 push @modules, \%module;
115 }
116  
117 2 ▶ $args{modules} = \@modules if @modules;
Branch: 1 branch
BranchTrueFalseTotal
if @modules 1 1 2
118  
119 2 return %args;
120 }
121  
122 4 ▶sub default_location { 'modules/03modlist.data.gz' }
Subroutine default_location: called CC=1 SCAR=0.0
Pod documented
123  
124 2 __PACKAGE__->meta->make_immutable;
125  
126  
127  
128  
129 =pod
130  
131 =head1 NAME
132  
133 CPAN::Index::API::File::ModList - Interface to 03modlist.data
134  
135 =head1 VERSION
136  
137 version 0.007
138  
139 =head1 SYNOPSIS
140  
141 my $modlist = CPAN::Index::File::ModList->parse_from_repo_uri(
142 'http://cpan.perl.org'
143 );
144  
145 foreach my $module ($modlist->modules) {
146 ... # do something
147 }
148  
149 =head1 DESCRIPTION
150  
151 This is a class to read and write 03modlist.data
152  
153 =head1 METHODS
154  
155 =head2 modules
156  
157 List of hashrefs containing module data. Each hashref has the following
158 structure.
159  
160 =over
161  
162 =item name
163  
164 Module name, e.g. C<Foo::Bar>.
165  
166 =item description
167  
168 Short description of the module.
169  
170 =item authorid
171  
172 CPAN id of the module author.
173  
174 =item chapterid
175  
176 Number of the chapter under which the module is classified. Valid options are:
177  
178 =over
179  
180 =item 2 - Perl Core Modules
181  
182 =item 3 - Development Support
183  
184 =item 4 - Operating System Interfaces
185  
186 =item 5 - Networking Devices IPC
187  
188 =item 6 -Data Type Utilities
189  
190 =item 7 - Database Interfaces
191  
192 =item 8 - User Interfaces
193  
194 =item 9 - Language Interfaces
195  
196 =item 10 - File Names Systems Locking
197  
198 =item 11 - String Lang Text Proc
199  
200 =item 12 - Opt Arg Param Proc
201  
202 =item 13 - Internationalization Locale
203  
204 =item 14 - Security and Encryption
205  
206 =item 15 - World Wide Web HTML HTTP CGI
207  
208 =item 16 - Server and Daemon Utilities
209  
210 =item 17 - Archiving and Compression
211  
212 =item 18 - Images Pixmaps Bitmaps
213  
214 =item 19 - Mail and Usenet News
215  
216 =item 20 - Control Flow Utilities
217  
218 =item 21 - File Handle Input Output
219  
220 =item 22 - Microsoft Windows Modules
221  
222 =item 23 - Miscellaneous Modules
223  
224 =item 24 - Commercial Software Interfaces
225  
226 =item 26 - Documentation
227  
228 =item 27 - Pragma
229  
230 =item 28 - Perl6
231  
232 =item 99 - Not In Modulelist
233  
234 =back
235  
236 =item development_stage
237  
238 Single character indicating the development stage of the module. Valid
239 options are:
240  
241 =over
242  
243 =item M - Mature (no rigorous definition)
244  
245 =item R - Released
246  
247 =item S - Standard, supplied with Perl 5
248  
249 =item a - Alpha testing
250  
251 =item b - Beta testing
252  
253 =item c - Under construction but pre-alpha (not yet released)
254  
255 =item i - Idea, listed to gain consensus or as a placeholder
256  
257 =back
258  
259 =item support_level
260  
261 Single character indicating the type of support provided for the module.
262 Valid options are:
263  
264 =over
265  
266 =item a - Abandoned, the module has been abandoned by its author
267  
268 =item d - Developer
269  
270 =item m - Mailing-list
271  
272 =item n - None known, try comp.lang.perl.modules
273  
274 =item u - Usenet newsgroup comp.lang.perl.modules
275  
276 =back
277  
278 =item language_used
279  
280 Single character indicating the programming languages used in the module.
281 Valid options are:
282  
283 =over
284  
285 =item + - C++ and perl, a C++ compiler will be needed
286  
287 =item c - C and perl, a C compiler will be needed
288  
289 =item h - Hybrid, written in perl with optional C code, no compiler needed
290  
291 =item o - perl and another language other than C or C++
292  
293 =item p - Perl-only, no compiler needed, should be platform independent
294  
295 =back
296  
297 =item interface_style
298  
299 Single character indicating the interface of the module. Valid options are:
300  
301 =over
302  
303 =item O - Object oriented using blessed references and/or inheritance
304  
305 =item f - plain Functions, no references used
306  
307 =item h - hybrid, object and function interfaces available
308  
309 =item n - no interface at all (huh?)
310  
311 =item r - some use of unblessed References or ties
312  
313 =back
314  
315 =item public_license
316  
317 Single character indicating the licence under which the module is distributed.
318 Valid options are:
319  
320 =over
321  
322 =item a - Artistic license alone
323  
324 =item b - BSD: The BSD License
325  
326 =item g - GPL: GNU General Public License
327  
328 =item l - LGPL: "GNU Lesser General Public License" (previously known as "GNU Library General Public License")
329  
330 =item o - other (but distribution allowed without restrictions)
331  
332 =item p - Standard-Perl: user may choose between GPL and Artistic
333  
334 =back
335  
336 =back
337  
338 =head2 module_count
339  
340 Number of modules indexed in the file.
341  
342 =head2 filename
343  
344 Name of this file - defaults to C<'03modlist.data.gz>;
345  
346 =head2 description
347  
348 Short description of the file.
349  
350 =head2 parse
351  
352 Parses the file and reurns its representation as a data structure.
353  
354 =head2 default_location
355  
356 Default file location - C<modules/03modlist.data.gz>.
357  
358 =head1 METHODS FROM ROLES
359  
360 =over
361  
362 =item <CPAN::Index::API::Role::Readable/read_from_string>
363  
364 =item <CPAN::Index::API::Role::Readable/read_from_file>
365  
366 =item <CPAN::Index::API::Role::Readable/read_from_tarball>
367  
368 =item <CPAN::Index::API::Role::Readable/read_from_repo_path>
369  
370 =item <CPAN::Index::API::Role::Readable/read_from_repo_uri>
371  
372 =item L<CPAN::Index::API::Role::Writable/tarball_is_default>
373  
374 =item L<CPAN::Index::API::Role::Writable/repo_path>
375  
376 =item L<CPAN::Index::API::Role::Writable/template>
377  
378 =item L<CPAN::Index::API::Role::Writable/content>
379  
380 =item L<CPAN::Index::API::Role::Writable/write_to_file>
381  
382 =item L<CPAN::Index::API::Role::Writable/write_to_tarball>
383  
384 =item L<CPAN::Index::API::Role::Clonable/clone>
385  
386 =item L<CPAN::Index::API::Role::HavingFilename/filename>
387  
388 =item L<CPAN::Index::API::Role::HavingGeneratedBy/generated_by>
389  
390 =item L<CPAN::Index::API::Role::HavingGeneratedBy/last_generated>
391  
392 =back
393  
394 =head1 AUTHOR
395  
396 Peter Shangov <pshangov@yahoo.com>
397  
398 =head1 COPYRIGHT AND LICENSE
399  
400 This software is copyright (c) 2012 by Venda, Inc..
401  
402 This is free software; you can redistribute it and/or modify it under
403 the same terms as the Perl 5 programming language system itself.
404  
405 =cut
406  
407  
408 __DATA__
409 File: [% $self->filename %]
410 Description: [% $self->description %]
411 Modcount: [% $self->module_count %]
412 Written-By: [% $self->generated_by %]
413 Date: [% $self->last_generated %]
414  
415 package CPAN::Modulelist;
416 # Usage: print Data::Dumper->new([CPAN::Modulelist->data])->Dump or similar
417 # cannot 'use strict', because we normally run under Safe
418 # use strict;
419 sub data {
420 my $result = {};
421 my $primary = "modid";
422 for (@$CPAN::Modulelist::data){
423 my %hash;
424 @hash{@$CPAN::Modulelist::cols} = @$_;
425 $result->{$hash{$primary}} = \%hash;
426 }
427 $result;
428 }
429 $CPAN::Modulelist::cols = [
430 'modid',
431 'statd',
432 'stats',
433 'statl',
434 'stati',
435 'statp',
436 'description',
437 'userid',
438 'chapterid'
439 ];
440  
441 [%
442 if ($self->module_count)
443 {
444 $OUT .= '$CPAN::Modulelist::data = [' . "\n";
445  
446 foreach my $module ($self->modules) {
447 $OUT .= sprintf "[\n'%s',\n'%s',\n'%s',\n'%s',\n'%s',\n'%s',\n'%s',\n'%s',\n'%s'\n],\n",
448 $module->{name},
449 $module->{development_stage} ? $module->{development_stage} : '?',
450 $module->{support_level} ? $module->{support_level} : '?',
451 $module->{language_used} ? $module->{language_used} : '?',
452 $module->{interface_style} ? $module->{interface_style} : '?',
453 $module->{public_license} ? $module->{public_license} : '?',
454 $module->{description},
455 $module->{authorid},
456 $module->{chapterid},
457 }
458  
459 $OUT .= "];\n"
460 }
461 else
462 {
463 $OUT .= '$CPAN::Modulelist::data = [];' . "\n";
464 }
465 %]
« API/Role/Writable.pm ↑ Summary API/File/PackagesDetails.pm »