Footprintless/Mixins.pm

filter: Statementstmt 63.7% 65 / 102 Branchbran 26.3% 10 / 38 Conditioncond 53.3% 8 / 15 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 69.2% 18 / 26 Podpod n/a totaltotal 54.2% 103 / 190 CC 26 SCAR 20.2
CC
26
Cov
54%
_deployment
20.0
_overlay
20.0
_service
20.0
CRAP 7.6
« Footprintless.pm ↑ Summary Footprintless/App/ActionCommand.pm »
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::Mixins;
5 11 $Footprintless::Mixins::VERSION = '1.29';
6 # ABSTRACT: A utility package for mixins for standard object
7 # PODNAME: Footprintless::Mixins
8  
9 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use File::Path qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 make_path
13 11 );
14 11 ▶use Footprintless::Command qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 cp_command
16 11 );
17 11 ▶use Footprintless::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
18 clean
19 dumper
20 extract
21 invalid_entity
22 rebase
23 temp_dir
24 11 );
25 11 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 11 our @EXPORT_OK = qw(
28 _clean
29 _command_options
30 _deployment
31 _download
32 _entity
33 _extract_resource
34 _is_local
35 _local_template
36 _overlay
37 _push_resource_to_destination
38 _push_to_destination
39 _resource
40 _run
41 _run_or_die
42 _service
43 _sub_coordinate
44 _sub_entity
45 _verify_required_entities
46 );
47  
48 11 my $logger = Log::Any->get_logger();
49  
50 11 ▶sub _clean {
Subroutine _clean: called CC=2 SCAR=7.0
51 11 my ( $self, %options ) = @_;
52 11 my $clean = _sub_entity( $self, 'clean' );
53 11 ▶ if ($clean) {
Branch: 1 branch
BranchTrueFalseTotal
if ($clean) 11 0 11
54 clean(
55 $clean,
56 command_runner => $self->{factory}->command_runner(),
57 command_options => _command_options($self),
58 rebase => $options{rebase}
59 11 );
60 }
61 }
62  
63 23 ▶sub _command_options {
Subroutine _command_options: called CC=2 SCAR=7.1
64 23 my ( $self, $sub_coordinate ) = @_;
65 my $entity =
66 $sub_coordinate
67 ? _sub_entity( $self, $sub_coordinate )
68 23 ▶ : _entity( $self, $self->{coordinate} );
Branch: 1 branch
BranchTrueFalseTotal
$sub_coordinate ? : 0 23 23
69 23 return $self->{factory}->command_options(%$entity);
70 }
71  
72 0 ▶sub _deployment {
Subroutine _deployment: not called CC=4 SCAR=30.0
73 0 my ( $self, $sub_coordinate, $name ) = @_;
74 0 ▶ my $deployment = $name ? $self->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 0 0 0
75 0 ▶ unless ($deployment) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($deployment) 0 0 0
76 0 $deployment = $self->{factory}->deployment( _sub_coordinate( $self, $sub_coordinate ) );
77 0 ▶ $self->{$name} = $deployment if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
78 }
79 0 return $deployment;
80 }
81  
82 17 ▶sub _download {
Subroutine _download: called CC=5 SCAR=16.2
83 17 my ( $self, $resource, $to ) = @_;
84 my @options =
85 $to
86 && ref($resource)
87 && $resource->{as}
88 17 ▶ ? ( to => File::Spec->catfile( $to, $resource->{as} ) )
Branch: 1 branch
BranchTrueFalseTotal
$to && ref $resource && $resource->{'as'} ? : 6 11 17
Condition83%5/6
$to and ref $resource and $resource->{"as"}
!ll&&!rl&&r
1106
$to and ref $resource
!ll&&!rl&&r
566
MC/DC66%2/3
$to and ref $resource and $resource->{"as"}
$to ref $resource $resource->{"as"}
Truth table75%3/4
A and B and C
A= $toB= ref $resourceC= $resource->{"as"}
ABCresult
0XX0
10X0
1100
1111
89 : ( to => $to );
90  
91 17 my $path = $self->{factory}->resource_manager()->download( $resource, @options );
92 17 ▶ die( "$path did not exist after _download of " . dumper($resource) ) unless ( -e $path );
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 17 17
93 17 $logger->debugf( 'Successfully downloaded resource %s to %s', $resource, $path );
94 17 return $path;
95  
96 # return $self->{factory}->resource_manager()->download($resource, @options);
97 }
98  
99 232 ▶sub _entity {
Subroutine _entity: called CC=3 SCAR=11.3
100 232 my ( $self, $coordinate, $required ) = @_;
101 232 my $entity = $self->{factory}->entities()->get_entity($coordinate);
102 232 ▶ invalid_entity( $coordinate, "does not exist" )
Branch: 1 branch
BranchTrueFalseTotal
if $required and not $entity 0 232 232
Condition66%2/3
$required and not $entity
!ll&&!rl&&r
189430
MC/DC0%0/2
$required and not $entity
$required not $entity
Truth table66%2/3
A and not(B)
A= $requiredB= not $entity
ABresult
0X0
100
111
103 if ( $required && !$entity );
104 232 return $entity;
105 }
106  
107 5 ▶sub _extract_resource {
Subroutine _extract_resource: called CC=1 SCAR=0.0
108 5 my ( $self, $resource, $to_dir ) = @_;
109 5 extract( _download( $self, $resource ), to => $to_dir );
110 }
111  
112 16 ▶sub _is_local {
Subroutine _is_local: called CC=1 SCAR=0.0
113 16 my ( $self, $hostname_sub_coordinate ) = @_;
114 return $self->{factory}->localhost()
115 16 ->is_alias( _sub_entity( $self, $hostname_sub_coordinate ) );
116 }
117  
118 17 ▶sub _local_template {
Subroutine _local_template: called CC=5 SCAR=16.6
119 17 my ( $self, $local_work, %options ) = @_;
120 my $destination_dir = $options{destination_dir}
121 17 ▶ || _sub_entity( $self, 'to_dir', 1 );
Condition33%1/3
$options{'destination_dir'} || _sub_entity($self, 'to_dir', 1)
l!l&&r!l&&!r
0170
MC/DC0%0/2
$options{'destination_dir'} || _sub_entity($self, 'to_dir', 1)
$options{'destination_dir'} _sub_entity($self, 'to_dir', 1)
Truth table33%1/3
A || B
A= $options{'destination_dir'}B= _sub_entity($self, 'to_dir', 1)
ABresult
1X1
011
000
122  
123 17 my ( $is_local, $to_dir );
124 17 ▶ if ( $options{rebase} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'rebase'}) { } 1 16 17
125 1 $to_dir = rebase( $destination_dir, $options{rebase} );
126 1 $is_local = 1;
127 }
128 else {
129 16 $is_local = _is_local( $self, 'hostname' );
130 16 ▶ $to_dir = $is_local ? $destination_dir : temp_dir();
Branch: 1 branch
BranchTrueFalseTotal
$is_local ? : 16 0 16
131 }
132  
133 17 &$local_work($to_dir);
134  
135 17 ▶ _push_to_destination( $self, $to_dir, $destination_dir ) unless ($is_local);
Branch: 1 branch
BranchTrueFalseTotal
unless $is_local 0 17 17
136 }
137  
138 0 ▶sub _overlay {
Subroutine _overlay: not called CC=4 SCAR=30.0
139 0 my ( $self, $sub_coordinate, $name ) = @_;
140 0 ▶ my $overlay = $name ? $self->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 0 0 0
141 0 ▶ unless ($overlay) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($overlay) 0 0 0
142 0 $overlay = $self->{factory}->overlay( _sub_coordinate( $self, $sub_coordinate ) );
143 0 ▶ $self->{$name} = $overlay if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
144 }
145 0 return $overlay;
146 }
147  
148 0 ▶sub _push_resource_to_destination {
Subroutine _push_resource_to_destination: not called CC=2 SCAR=17.9
149 0 my ( $self, $resource, $destination_dir, %options ) = @_;
150  
151 0 my $temp_dir = temp_dir();
152 0 ▶ if ( $options{extract} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'extract'}) { } 0 0 0
153 0 _extract_resource( $self, $resource, $temp_dir );
154 }
155 else {
156 0 _download( $self, $resource, $temp_dir );
157 }
158  
159 0 _push_to_destination( $self, $temp_dir, $destination_dir, %options );
160 }
161  
162 0 ▶sub _push_to_destination {
Subroutine _push_to_destination: not called CC=3 SCAR=24.8
163 0 my ( $self, $source_dir, $destination_dir, %options ) = @_;
164  
165 0 my %copy_options = ();
166 0 my %runner_options = ();
167  
168 0 ▶ if ( $options{status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"status"}) 0 0 0
169 0 $copy_options{status} = $options{status};
170 0 $runner_options{err_handle} = \*STDERR;
171 }
172  
173 _run_or_die(
174 $self,
175 cp_command(
176 $source_dir, $destination_dir,
177 0 ▶ $options{command_options} || _command_options($self), %copy_options
Condition0%0/3
$options{'command_options'} || _command_options($self)
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{'command_options'} || _command_options($self)
$options{'command_options'} _command_options($self)
Truth table0%0/3
A || B
A= $options{'command_options'}B= _command_options($self)
ABresult
1X1
011
000
178 ),
179 \%runner_options
180 );
181 }
182  
183 0 ▶sub _resource {
Subroutine _resource: not called CC=1 SCAR=6.9
184 0 my ( $self, $resource ) = @_;
185 0 return $self->{factory}->resource_manager()->resource($resource);
186 }
187  
188 0 ▶sub _run {
Subroutine _run: not called CC=1 SCAR=6.9
189 0 my ( $self, $command, @runner_options ) = @_;
190 0 return $self->{factory}->command_runner()->run( $command, @runner_options );
191 }
192  
193 24 ▶sub _run_or_die {
Subroutine _run_or_die: called CC=1 SCAR=0.0
194 24 my ( $self, $command, @runner_options ) = @_;
195 24 return $self->{factory}->command_runner()->run_or_die( $command, @runner_options );
196 }
197  
198 0 ▶sub _service {
Subroutine _service: not called CC=4 SCAR=30.0
199 0 my ( $self, $sub_coordinate, $name ) = @_;
200 0 ▶ my $service = $name ? $self->{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$name ? : 0 0 0
201 0 ▶ unless ($service) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service) 0 0 0
202 0 $service = $self->{factory}->service( _sub_coordinate( $self, $sub_coordinate ) );
203 0 ▶ $self->{$name} = $service if ($name);
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 0 0
204 }
205 0 return $service;
206 }
207  
208 135 ▶sub _sub_coordinate {
Subroutine _sub_coordinate: called CC=1 SCAR=0.0
209 135 my ( $self, $sub_coordinate ) = @_;
210 135 return "$self->{coordinate}.$sub_coordinate";
211 }
212  
213 135 ▶sub _sub_entity {
Subroutine _sub_entity: called CC=1 SCAR=0.0
214 135 my ( $self, $sub_coordinate, $required ) = @_;
215 135 return _entity( $self, _sub_coordinate( $self, $sub_coordinate ), $required );
216 }
217  
218 0 ▶sub _verify_required_entities {
Subroutine _verify_required_entities: not called CC=2 SCAR=17.9
219 0 my ( $self, @sub_coordinates ) = @_;
220 0 _sub_entity( $self, $_, 1 ) foreach @sub_coordinates;
221 }
222  
223 11 1;
224  
225 __END__
« Footprintless.pm ↑ Summary Footprintless/App/ActionCommand.pm »