File Coverage

blib/lib/PAUSE/Users/UserIterator.pm
Criterion Covered Total %
statement 46 46 100.0
branch 14 14 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 68 69 98.5


line stmt bran cond sub pod time code
1             package PAUSE::Users::UserIterator;
2             $PAUSE::Users::UserIterator::VERSION = '0.11';
3 2     2   12 use strict;
  2         4  
  2         52  
4 2     2   9 use warnings;
  2         4  
  2         36  
5 2     2   20 use 5.14.0;
  2         5  
6              
7 2     2   9 use Moo;
  2         3  
  2         16  
8 2     2   1285 use PAUSE::Users::User;
  2         7  
  2         50  
9 2     2   873 use autodie;
  2         35939  
  2         8  
10 2     2   11368 use feature 'unicode_strings';
  2         4  
  2         976  
11              
12             has 'users' => ( is => 'ro' );
13             has _fh => ( is => 'rw' );
14              
15             sub next_user
16             {
17 14278     14278 0 71155 my $self = shift;
18 14278         24382 my @fields;
19             my $inuser;
20 14278         0 my $fh;
21 14278         16787 local $_;
22              
23 14278 100       28295 if (not defined $self->_fh) {
24 2         13 $fh = $self->users->open_file();
25 2         22335 $self->_fh($fh);
26             }
27             else {
28 14276         18593 $fh = $self->_fh;
29             }
30              
31 14278         15955 $inuser = 0;
32             LINE:
33 14278         37231 while (<$fh>) {
34              
35 113706 100       211548 if (m!!) {
36 14304         16426 $inuser = 1;
37 14304         32215 next LINE;
38             }
39              
40 99402 100       133760 next LINE unless $inuser;
41              
42 99238 100       307060 if (m!<([a-zA-Z0-6_]+)>(.*?)!) {
43 84962         181566 my ($field, $value) = ($1, $2);
44              
45             # author specified a user account
46             # list is a mailing list; we skip those
47 84962 100       123533 if ($field eq 'type') {
48 14304 100       20954 $inuser = 0 if $value eq 'list';
49 14304         36571 next LINE;
50             }
51              
52 70658         111659 push(@fields, $field => $value);
53             }
54              
55 84934 100       218917 if (m!!) {
56 14276         218388 my $user = PAUSE::Users::User->new(@fields);
57 14276         170381 @fields = ();
58 14276         27235 return $user;
59             }
60              
61             }
62 2         15 close($fh);
63 2         3437 return undef;
64             }
65              
66             1;