File Coverage

blib/lib/File/IsSorted.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition 3 5 60.0
subroutine 9 9 100.0
pod 2 2 100.0
total 49 51 96.0


line stmt bran cond sub pod time code
1             package File::IsSorted;
2             $File::IsSorted::VERSION = '0.0.5';
3 2     2   105272 use strict;
  2         15  
  2         56  
4 2     2   11 use warnings;
  2         4  
  2         57  
5 2     2   9 use autodie;
  2         4  
  2         16  
6 2     2   10948 use 5.016;
  2         16  
7 2     2   1012 no locale;
  2         1187  
  2         11  
8              
9 2     2   1137 use Moo;
  2         22652  
  2         9  
10              
11 2     2   3551 use Path::Tiny qw/ path /;
  2         7  
  2         493  
12              
13             sub is_filehandle_sorted
14             {
15 5     5 1 22287 my ( $self, $args ) = @_;
16              
17 5         13 my $fh = $args->{fh};
18 5   100     18 my $id = $args->{id} // 'unknown';
19              
20 5         49 my $prev = <$fh>;
21 5         24 while ( my $l = <$fh> )
22             {
23 15 100       35 if ( $l le $prev )
24             {
25 1         25 die "<$l> less-or-equal than <$prev> in $id!";
26             }
27             }
28             continue
29             {
30 14         51 $prev = $l;
31             }
32              
33 4         36 return 1;
34             }
35              
36             sub is_file_sorted
37             {
38 4     4 1 1875 my ( $self, $args ) = @_;
39              
40 4         11 my $path = $args->{path};
41 4   33     43 my $id = $args->{id} // $path;
42              
43 4         18 return $self->is_filehandle_sorted(
44             { fh => path($path)->openr, id => $id } );
45             }
46              
47             1;
48              
49             __END__