blib/lib/Parse/CVSEntries.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 100% 50 / 50 CC 2 SCAR 1.8
CC
2
Cov
100%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Parse::CVSEntries;
3 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 $VERSION = '0.03';
5  
6 =head1 NAME
7  
8 Parse::CVSEntries - parse a CVS/Entries file
9  
10 =head1 SYNOPSIS
11  
12 my $parsed = Parse::CVSEntries->new( 'CVS/Entries' );
13 for my $entry ($parsed->entries) {
14 print $entry->name, " ", $entry->version, "\n";
15 }
16  
17 =head1 DESCRIPTION
18  
19 =cut
20  
21 =head1 METHODS
22  
23 =head2 new( $file )
24  
25 Opens a file and parses it invoking C<< entry_class->new >> to
26 actually prepare the data.
27  
28 =cut
29  
30 3 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
31 3 my $class = shift;
32 3 my $filename = shift;
33 3 ▶ open my $fh, "<$filename" or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<$filename" or return 2 1 3
34 2 my @entries = map { chomp; $class->entry_class->new($_) } <$fh>;
35 2 bless \@entries, $class;
36 }
37  
38 =head2 entries
39  
40 Returns a list of all the entries in the parsed file.
41  
42 =cut
43  
44 3 ▶sub entries {
Subroutine entries: called CC=1 SCAR=0.0
Pod documented
45 3 @{ $_[0] }
46 }
47  
48 =head2 entry_class
49  
50 What class to instantiate for each entry. Defaults to C<Parse::CVSEntry>
51  
52 =cut
53  
54 15 ▶sub entry_class {
Subroutine entry_class: called CC=1 SCAR=0.0
Pod documented
55 15 'Parse::CVSEntry';
56 }
57  
58 =head1 Parse::CVSEntry
59  
60 A representation of an entry in the entries file.
61  
62 =head1 METHODS
63  
64 All of these are just simple data accessors.
65  
66 =head2 dir
67  
68 =head2 name
69  
70 =head2 version
71  
72 =head2 modified
73  
74 =head2 mtime
75  
76 C<modified> as epoch seconds
77  
78 =cut
79  
80 package Parse::CVSEntry;
81 1 ▶use Class::Accessor::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 ▶use Date::Parse qw( str2time );
Subroutine BEGIN: called CC=1 SCAR=0.0
84  
85 # the actual fields in the file
86 1 my @fields = qw( dir name version modified bar baz );
87 1 __PACKAGE__->mk_accessors( @fields, qw( mtime ) );
88  
89 15 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
90 15 my $class = shift;
91 15 my $line = shift;
92  
93 15 my %self;
94 15 @self{ @fields } = split /\//, $_;
95 15 my $new = $class->SUPER::new(\%self);
96  
97 15 $new->mtime( str2time $new->modified, "UTC" );
98 15 return $new;
99 }
100  
101 1 1;
102 __END__
↑ Summary