TaskPipe/Template.pm

filter: Statementstmt 26.4% 9 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 2 / 8 Podpod 0.0% 0 / 5 totaltotal 18.3% 11 / 60 CC 6 SCAR 19.6
CC
6
Cov
20%
deploy
12.0
write_file
12.0
target_dir
6.0
CRAP 7.1
« TaskPipe/Role/MooseType_UserAgentType.pm ↑ Summary TaskPipe/ThreadManager.pm »
1 package TaskPipe::Template;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 has path_settings => (is => 'ro', isa => 'TaskPipe::PathSettings', lazy => 1, default => sub{
7 0 ▶ TaskPipe::PathSettings->new;
Subroutine __ANON__: not called CC=1 SCAR=6.9
8 1 });
9  
10  
11 sub target_filename{
12 0 ▶ my ($self) = @_;
Subroutine target_filename: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 0 my $target_filename = $self->path_settings->filename( $self->filename_label );
15 0 return $target_filename;
16 }
17  
18  
19 sub target_dir{
20 0 ▶ my ($self) = @_;
Subroutine target_dir: not called CC=2 SCAR=17.9
Pod undocumented
21  
22 0 my $target_dir = $self->path_settings->path( $self->dir_label );
23 0 ▶ confess "Target dir $target_dir does not exist" unless -d $target_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $target_dir 0 0 0
24 0 return $target_dir;
25 }
26  
27  
28 sub target_path{
29 0 ▶ my ($self) = @_;
Subroutine target_path: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 return +File::Spec->catdir( $self->target_dir, $self->target_filename );
32 }
33  
34  
35 sub deploy{
36 0 ▶ my ($self) = @_;
Subroutine deploy: not called CC=3 SCAR=24.8
Pod undocumented
37  
38 0 my $nest = Template::Nest->new;
39  
40 0 $nest->template_hash({
41 template => +$self->template
42 });
43
44 0 my $to_render = { NAME => 'template' };
45  
46 0 ▶ if ( $self->can('template_vars') && $self->template_vars ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("template_vars") and $self->template_vars) 0 0 0
Condition0%0/3
$self->can("template_vars") and $self->template_vars
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can("template_vars") and $self->template_vars
$self->can("template_vars") $self->template_vars
Truth table0%0/3
A and B
A= $self->can("template_vars")B= $self->template_vars
ABresult
0X0
100
111
47 0 $to_render = { %$to_render, %{$self->template_vars} };
48 }
49
50 0 $self->write_file( $nest->render($to_render) );
51 }
52  
53  
54  
55  
56 sub write_file{
57 0 ▶ my ($self,$text) = @_;
Subroutine write_file: not called CC=3 SCAR=24.8
Pod undocumented
58  
59 0 my $target_path = $self->target_path;
60  
61 0 ▶ confess "target path $target_path already exists" if -f $target_path;
Branch: 1 branch
BranchTrueFalseTotal
if -f $target_path 0 0 0
62  
63 0 my $fh;
64 0 ▶ open $fh,'>',$target_path or confess "Could not open $target_path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $target_path or confess("Could not open ${target_path}: $!") 0 0 0
65  
66 0 print $fh $text;
67 0 close $fh;
68 }
69  
70  
71 =head1 NAME
72  
73 TaskPipe::Template - the base class for file templates
74  
75 =head1 DESCRIPTION
76  
77 Inherit from this class to create a new file template for deployment. You need to add a C<deploy> method, which will write the file at C<target_path>.
78  
79 =head1 AUTHOR
80  
81 Tom Gracey <tomgracey@gmail.com>
82  
83 =head1 COPYRIGHT AND LICENSE
84  
85 Copyright (c) Tom Gracey 2018
86  
87 TaskPipe is free software, licensed under
88  
89 The GNU Public License Version 3
90  
91 =cut
92  
93 1 __PACKAGE__->meta->make_immutable;
94 1 1;
95  
96  
« TaskPipe/Role/MooseType_UserAgentType.pm ↑ Summary TaskPipe/ThreadManager.pm »