File Coverage

lib/Perlmazing/Perlmazing/slurp.pm
Criterion Covered Total %
statement 23 23 100.0
branch 8 10 80.0
condition 3 6 50.0
subroutine 3 3 100.0
pod 0 1 0.0
total 37 43 86.0


line stmt bran cond sub pod time code
1 2     2   15 use Perlmazing qw(croak);
  2         3  
  2         13  
2              
3             sub main {
4 3     3 0 6 my $file = shift;
5 3         5 my $binary = shift;
6 3         4 my $encoding;
7             {
8 2     2   12 no warnings 'numeric';
  2         2  
  2         573  
  3         4  
9 3 100 66     13 if ($binary and ($binary + 0) == 0) {
10 1         2 $encoding = $binary;
11 1         2 undef $binary;
12             }
13             }
14 3 100       112 croak "File '$file' cannot be read: $!" unless open my $in, '<'.($encoding ? ":encoding($encoding)" : ''), $file;
    50          
15 3 50 33     208 binmode $in if -B $file or $binary;
16 3 100       10 if (wantarray) {
17 2         27 my @data = <$in>;
18 2         11 close $in;
19 2         24 return @data;
20             } else {
21 1         5 local $/ = undef;
22 1         19 my $data = <$in>;
23 1         18 close $in;
24 1         7 return $data;
25             }
26             }
27              
28             1;