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.16';
3 2     2   12 use Moo;
  2         4  
  2         21  
4 2     2   657 use CPAN::ReleaseHistory;
  2         6  
  2         46  
5 2     2   9 use CPAN::ReleaseHistory::Release;
  2         3  
  2         59  
6 2     2   11 use CPAN::DistnameInfo;
  2         3  
  2         38  
7 2     2   6 use autodie;
  2         4  
  2         12  
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 3549 my $self = shift;
26 19         30 my $fh;
27 19         25 local $_;
28              
29 19 100       54 if (not defined $self->_fh) {
30 2         12 $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         20476 my $header_line = <$fh>;
35 2         28 $self->_fh($fh);
36             }
37             else {
38 17         28 $fh = $self->_fh;
39             }
40              
41             RELEASE:
42 19         26 while (1) {
43 20         110 my $line = <$fh>;
44              
45 20 100       40 if (defined($line)) {
46 18         30 chomp($line);
47 18         101 my ($path, $time, $size) = split(/\s+/, $line);
48 18         47 my @args = (path => $path, timestamp => $time, size => $size);
49              
50 18 100       49 if ($self->well_formed) {
51 9         28 my $distinfo = CPAN::DistnameInfo->new($path);
52              
53 9 100 66     602 next RELEASE unless defined($distinfo)
      66        
54             && defined($distinfo->dist)
55             && defined($distinfo->cpanid);
56 8         64 push(@args, distinfo => $distinfo);
57             }
58              
59 17         254 return CPAN::ReleaseHistory::Release->new(@args);
60             } else {
61 2         12 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