| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::TimelogTxt::File; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 53195 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 4 | 2 |  |  | 2 |  | 6 | use strict; | 
|  | 2 |  |  |  |  | 1 |  | 
|  | 2 |  |  |  |  | 410 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = '0.20'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 14 |  |  | 14 | 1 | 3571 | my ($class, $fh, $start, $end) = @_; | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 14 | 100 |  |  |  | 33 | die "Missing required file handle or file name.\n" unless defined $fh; | 
| 12 | 13 | 100 |  |  |  | 22 | die "Missing required start marker.\n" unless defined $start; | 
| 13 | 12 | 100 |  |  |  | 24 | die "Missing required end marker.\n" unless defined $end; | 
| 14 | 11 | 50 |  |  |  | 15 | if( !ref $fh ) { | 
| 15 | 0 |  |  |  |  | 0 | my $name = $fh; | 
| 16 | 0 | 0 |  |  |  | 0 | open( $fh, '<', $name ) or die "Unable to open file '$name': $!\n"; | 
| 17 |  |  |  |  |  |  | } | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 11 |  |  |  |  | 33 | my $obj = { | 
| 20 |  |  |  |  |  |  | fh => $fh, | 
| 21 |  |  |  |  |  |  | start => $start, | 
| 22 |  |  |  |  |  |  | startlen => length $start, | 
| 23 |  |  |  |  |  |  | end => $end, | 
| 24 |  |  |  |  |  |  | endlen => length $end, | 
| 25 |  |  |  |  |  |  | stage => 0, | 
| 26 |  |  |  |  |  |  | }; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 11 |  |  |  |  | 23 | return bless $obj, $class; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | sub readline { | 
| 32 | 43 |  |  | 43 | 1 | 62 | my ($self) = @_; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 43 | 100 | 100 |  |  | 200 | return if $self->{'stage'} > 1 or eof( $self->{'fh'} ); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 35 |  |  |  |  | 28 | my $line; | 
| 37 | 35 | 100 |  |  |  | 46 | if( $self->{'stage'} == 0 ) | 
| 38 |  |  |  |  |  |  | { | 
| 39 | 11 |  | 100 |  |  | 259 | 0 while( defined( $line = readline $self->{'fh'} ) && substr( $line, 0, $self->{'startlen'} ) lt $self->{'start'} ); | 
| 40 | 11 |  |  |  |  | 11 | $self->{'stage'} = 1; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | else | 
| 43 |  |  |  |  |  |  | { | 
| 44 | 24 |  |  |  |  | 42 | $line = readline $self->{'fh'}; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 35 | 100 | 100 |  |  | 209 | return $line if !defined $line || substr( $line, 0, $self->{'endlen'} ) lt $self->{'end'}; | 
| 48 | 9 |  |  |  |  | 8 | $self->{'stage'} = 2; | 
| 49 | 9 |  |  |  |  | 40 | return; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | 1; | 
| 53 |  |  |  |  |  |  | __END__ |