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   111 use 5.008;
  8         25  
4              
5 8     8   32 use strict;
  8         136  
  8         175  
6 8     8   28 use warnings;
  8         122  
  8         459  
7              
8 8     8   33 use parent qw{ Template::Provider };
  8         10  
  8         39  
9              
10 8     8   85840 use Astro::App::Satpass2::Utils qw{ :os @CARP_NOT };
  8         18  
  8         1078  
11              
12             our $VERSION = '0.057_02';
13              
14 8         1527 use constant ENCODING => OS_IS_WINDOWS ?
15             ':crlf:encoding(utf-8)' :
16 8     8   40 ':encoding(utf-8)';
  8         11  
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   338 my ($self, $path) = @_;
25              
26 2 50       6 return (undef, "No path specified to fetch content from ")
27             unless $path;
28              
29 2         34 my $data;
30             my $mod_date;
31 2         0 my $error;
32              
33 2         6 local *FH;
34 2 50       97 if(-d $path) {
    50          
35 0         0 $error = "$path: not a file";
36             }
37             elsif (open(FH, "<", $path)) {
38 2         9 local $/;
39 2     1   39 binmode(FH, ENCODING);
  1         561  
  1         14  
  1         5  
40 2         1038 $data = ;
41 2         42 $mod_date = (stat($path))[9];
42 2         27 close(FH);
43             }
44             else {
45 0         0 $error = "$path: $!";
46             }
47              
48             return wantarray
49 2 50       16 ? ( $data, $error, $mod_date )
50             : $data;
51             }
52              
53             ## use critic
54              
55             1;
56              
57             __END__