File Coverage

blib/lib/Astro/App/Satpass2/Format/Template/Provider.pm
Criterion Covered Total %
statement 32 34 94.1
branch 4 8 50.0
condition n/a
subroutine 8 8 100.0
pod n/a
total 44 50 88.0


line stmt bran cond sub pod time code
1             package Astro::App::Satpass2::Format::Template::Provider;
2              
3 8     8   147 use 5.008;
  8         33  
4              
5 8     8   55 use strict;
  8         21  
  8         586  
6 8     8   70 use warnings;
  8         17  
  8         518  
7              
8 8     8   62 use parent qw{ Template::Provider };
  8         15  
  8         249  
9              
10 8     8   123394 use Astro::App::Satpass2::Utils qw{ :os @CARP_NOT };
  8         480  
  8         1577  
11              
12             our $VERSION = '0.057';
13              
14 8         2014 use constant ENCODING => OS_IS_WINDOWS ?
15             ':crlf:encoding(utf-8)' :
16 8     8   67 ':encoding(utf-8)';
  8         20  
17              
18             # Cribbed **ALMOST** verbatim from Template::Provider. The only
19             # difference is the binmode() call, which applies I/O layers as
20             # convenient.
21             ## no critic (UnusedPrivateSubroutines,UnusedVarsStricter,ProhibitBarewordFileHandles,ProhibitInterpolationOfLiterals)
22              
23             sub _template_content {
24 2     2   477 my ($self, $path) = @_;
25              
26 2 50       5 return (undef, "No path specified to fetch content from ")
27             unless $path;
28              
29 2         7 my $data;
30             my $mod_date;
31 2         0 my $error;
32              
33 2         6 local *FH;
34 2 50       89 if(-d $path) {
    50          
35 0         0 $error = "$path: not a file";
36             }
37             elsif (open(FH, "<", $path)) {
38 2         11 local $/;
39 2     1   68 binmode(FH, ENCODING);
  1         546  
  1         12  
  1         5  
40 2         1075 $data = ;
41 2         45 $mod_date = (stat($path))[9];
42 2         29 close(FH);
43             }
44             else {
45 0         0 $error = "$path: $!";
46             }
47              
48             return wantarray
49 2 50       17 ? ( $data, $error, $mod_date )
50             : $data;
51             }
52              
53             ## use critic
54              
55             1;
56              
57             __END__