File Coverage

blib/lib/CPAN/PackageDetails/Entry.pm
Criterion Covered Total %
statement 18 21 85.7
branch 2 2 100.0
condition n/a
subroutine 7 10 70.0
pod 6 6 100.0
total 33 39 84.6


line stmt bran cond sub pod time code
1             package CPAN::PackageDetails::Entry;
2 13     13   897 use strict;
  13         21  
  13         282  
3 13     13   55 use warnings;
  13         19  
  13         391  
4              
5             our $VERSION = '0.261';
6              
7 13     13   54 use Carp;
  13         17  
  13         2262  
8              
9             =encoding utf8
10              
11             =head1 NAME
12              
13             CPAN::PackageDetails::Entry - Handle a single record of 02packages.details.txt.gz
14              
15             =head1 SYNOPSIS
16              
17             Used internally by CPAN::PackageDetails
18              
19             =head1 DESCRIPTION
20              
21             An entry is a single line from F<02packages.details.txt> that maps a
22             package name to a source. It's a whitespace-separated list that
23             has the values for the column identified in the "columns" field
24             in the header.
25              
26             By default, there are three columns: package name, version, and path.
27              
28             Inside a CPAN::PackageDetails object, the actual work and
29             manipulation of the entries are handled by delegate classes specified
30             in C and C). At the moment these are
31             immutable, so you'd have to subclass this module to change them.
32              
33             =head2 Methods
34              
35             =over 4
36              
37             =item new( FIELD1 => VALUE1 [, FIELD2 => VALUE2] )
38              
39             Create a new entry
40              
41             =cut
42              
43             sub new {
44 1477     1477 1 2790 my( $class, %args ) = @_;
45              
46 1477         7337 bless { %args }, $class
47             }
48              
49             =item path
50              
51             =item author
52              
53             =item version
54              
55             =item package_name
56              
57             Access values of the entry.
58              
59             =cut
60              
61 14     14 1 23 sub path { $_[0]->{path} }
62 0     0 1 0 sub author { ( split m|/|, $_[0]->{path} )[2] }
63 0     0 1 0 sub version { $_[0]->{version} }
64 0     0 1 0 sub package_name { $_[0]->{'package name'} }
65              
66             =item as_string( @column_names )
67              
68             Formats the Entry as text. It joins with whitespace the values for the
69             column names you pass it. You get the newline automatically.
70              
71             Any values that are not defined (or the empty string) turn into the
72             literal string 'undef' to preserve the columns in the output.
73              
74             =cut
75              
76             sub as_string {
77 9     9 1 422 my( $self, @columns ) = @_;
78              
79 13     13   74 no warnings 'uninitialized';
  13         28  
  13         894  
80             # can't check defined() because that let's the empty string through
81              
82             return sprintf "%-34s %5s %s\n",
83 9 100       16 map { length $self->{$_} ? $self->{$_} : 'undef' } @columns;
  27         93  
84             }
85              
86             =back
87              
88             =head1 TO DO
89              
90             =head1 SEE ALSO
91              
92              
93             =head1 SOURCE AVAILABILITY
94              
95             This source is in Github:
96              
97             https://github.com/briandfoy/cpan-packagedetails
98              
99             =head1 AUTHOR
100              
101             brian d foy, C<< >>
102              
103             =head1 COPYRIGHT AND LICENSE
104              
105             Copyright © 2009-2018, brian d foy . All rights reserved.
106              
107             You may redistribute this under the terms of the Artistic License 2.0.
108              
109             =cut
110              
111             1;
112              
113