File Coverage

blib/lib/CPAN/ReleaseHistory/ReleaseIterator.pm
Criterion Covered Total %
statement 35 35 100.0
branch 8 8 100.0
condition 4 6 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 53 56 94.6


line stmt bran cond sub pod time code
1             package CPAN::ReleaseHistory::ReleaseIterator;
2             $CPAN::ReleaseHistory::ReleaseIterator::VERSION = '0.15';
3 2     2   6 use Moo;
  2         3  
  2         11  
4 2     2   502 use CPAN::ReleaseHistory;
  2         2  
  2         36  
5 2     2   7 use CPAN::ReleaseHistory::Release;
  2         2  
  2         31  
6 2     2   6 use CPAN::DistnameInfo;
  2         2  
  2         32  
7 2     2   5 use autodie;
  2         3  
  2         11  
8              
9             has 'history' =>
10             (
11             is => 'ro',
12             default => sub { return PAUSE::Packages->new(); },
13             );
14              
15             has 'well_formed' =>
16             (
17             is => 'ro',
18             default => sub { 0 },
19             );
20              
21             has _fh => ( is => 'rw' );
22              
23             sub next_release
24             {
25 19     19 0 2947 my $self = shift;
26 19         16 my $fh;
27 19         16 local $_;
28              
29 19 100       50 if (not defined $self->_fh) {
30 2         11 $fh = $self->history->open_file();
31              
32             # skip the header line.
33             # TODO: should confirm that it's the format we expect / support
34 2         16068 my $header_line = <$fh>;
35 2         36 $self->_fh($fh);
36             }
37             else {
38 17         19 $fh = $self->_fh;
39             }
40              
41             RELEASE:
42 19         15 while (1) {
43 20         66 my $line = <$fh>;
44              
45 20 100       27 if (defined($line)) {
46 18         22 chomp($line);
47 18         78 my ($path, $time, $size) = split(/\s+/, $line);
48 18         36 my @args = (path => $path, timestamp => $time, size => $size);
49              
50 18 100       40 if ($self->well_formed) {
51 9         20 my $distinfo = CPAN::DistnameInfo->new($path);
52              
53 9 100 66     438 next RELEASE unless defined($distinfo)
      66        
54             && defined($distinfo->dist)
55             && defined($distinfo->cpanid);
56 8         67 push(@args, distinfo => $distinfo);
57             }
58              
59 17         241 return CPAN::ReleaseHistory::Release->new(@args);
60             } else {
61 2         6 return undef;
62             }
63             }
64             }
65              
66             1;
67              
68             =head1 NAME
69              
70             CPAN::ReleaseHistory::ReleaseIterator - Release iterator for CPAN::ReleaseHistory.
71              
72             =head1 DESCRIPTION
73              
74             B
75              
76             =head1 REPOSITORY
77              
78             L
79              
80             =head1 AUTHOR
81              
82             Neil Bowers Eneilb@cpan.orgE
83              
84             =head1 COPYRIGHT AND LICENSE
85              
86             This software is copyright (c) 2014 by Neil Bowers .
87              
88             This is free software; you can redistribute it and/or modify it under
89             the same terms as the Perl 5 programming language system itself.
90              
91             =cut