File Coverage

blib/lib/SweetPea/Cli/Util.pm
Criterion Covered Total %
statement 18 35 51.4
branch 0 4 0.0
condition n/a
subroutine 6 9 66.6
pod 0 3 0.0
total 24 51 47.0


line stmt bran cond sub pod time code
1             package SweetPea::Cli::Util;
2              
3 1     1   8 use warnings;
  1         3  
  1         44  
4 1     1   6 use strict;
  1         3  
  1         89  
5              
6 1     1   8 use Cwd qw(getcwd);
  1         2  
  1         299  
7 1     1   2077 use File::ShareDir ':ALL';
  1         19042  
  1         309  
8 1     1   12989 use File::Util;
  1         64441  
  1         7  
9 1     1   18720 use Template;
  1         39076  
  1         214  
10              
11             # SweetPea::Cli::Util - Common Functions for SweetPea-Cli
12              
13             sub new {
14 0     0 0   my $class = shift;
15 0           my $self = {};
16 0           bless $self, $class;
17 0           return $self;
18             }
19              
20             # template
21             #
22             # Load templates for terminal screen display.
23             # Takes 2 args
24             # - 1 template (scalar)
25             # - 2 stash (hashref)
26             # Returns 1 scalar
27            
28             sub template {
29 0     0 0   my $self = shift;
30 0           my $file = shift;
31 0           my $stash = shift;
32 0           my $t = Template->new(
33             EVAL_PERL => 1,
34             ABSOLUTE => 1,
35             ANYCASE => 1
36             );
37 0           my $content;
38            
39 0           $file = "templates/" . $file;
40 0 0         $file = -e "files/$file" ?
41             "files/$file" : dist_file('SweetPea-Cli', $file);
42 0           $t->process($file, {
43             's' => $stash
44             }, \$content);
45            
46 0           return $content;
47             }
48              
49             sub makefile {
50 0     0 0   my $self = shift;
51 0           my @data = @_;
52 0           my $f = File::Util->new;
53 0 0         $f->write_file(@data) unless -e $data[1];
54             }
55              
56             1; # End of SweetPea::Cli::Util