File Coverage

blib/lib/CPAN/PackageDetails/Entry.pm
Criterion Covered Total %
statement 20 23 86.9
branch 2 2 100.0
condition n/a
subroutine 8 11 72.7
pod 6 6 100.0
total 36 42 85.7


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