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.09';
3 2     2   15 use strict;
  2         4  
  2         62  
4 2     2   12 use warnings;
  2         3  
  2         47  
5 2     2   23 use 5.14.0;
  2         7  
6              
7 2     2   10 use Moo;
  2         4  
  2         12  
8 2     2   705 use PAUSE::Users::User;
  2         4  
  2         76  
9 2     2   1040 use autodie;
  2         29430  
  2         12  
10 2     2   13868 use feature 'unicode_strings';
  2         5  
  2         1207  
11              
12             has 'users' => ( is => 'ro' );
13             has _fh => ( is => 'rw' );
14              
15             sub next_user
16             {
17 13974     13974 0 78941 my $self = shift;
18 13974         29345 my @fields;
19             my $inuser;
20 13974         0 my $fh;
21 13974         17881 local $_;
22              
23 13974 100       29695 if (not defined $self->_fh) {
24 2         12 $fh = $self->users->open_file();
25 2         22160 $self->_fh($fh);
26             }
27             else {
28 13972         20743 $fh = $self->_fh;
29             }
30              
31 13974         19457 $inuser = 0;
32             LINE:
33 13974         42152 while (<$fh>) {
34              
35 111435 100       253630 if (m!!) {
36 14000         18300 $inuser = 1;
37 14000         36309 next LINE;
38             }
39              
40 97435 100       157389 next LINE unless $inuser;
41              
42 97271 100       352509 if (m!<([a-zA-Z0-6_]+)>(.*?)!) {
43 83299         209549 my ($field, $value) = ($1, $2);
44              
45             # author specified a user account
46             # list is a mailing list; we skip those
47 83299 100       148604 if ($field eq 'type') {
48 14000 100       24391 $inuser = 0 if $value eq 'list';
49 14000         40830 next LINE;
50             }
51              
52 69299         123942 push(@fields, $field => $value);
53             }
54              
55 83271 100       246328 if (m!!) {
56 13972         253590 my $user = PAUSE::Users::User->new(@fields);
57 13972         202547 @fields = ();
58 13972         31157 return $user;
59             }
60              
61             }
62 2         18 close($fh);
63 2         3889 return undef;
64             }
65              
66             1;