Sky/Manager.pm

filter: Statementstmt 95.9% 71 / 74 Branchbran 77.7% 14 / 18 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 17 / 17 Podpod 100% 2 / 2 totaltotal 93.8% 107 / 114 CC 11 SCAR 9.8
CC
11
Cov
93%
_calc_sect_name
5.2
_perform_upload_generic
5.1
_calc_target_dir
2.0
CRAP 2.7
« Sky/Module.pm ↑ Summary Sky.pm »
1 package App::Sky::Manager;
2 3 $App::Sky::Manager::VERSION = '0.8.0';
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use App::Sky::Module ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # For defined-or - "//".
19 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 has config => ( isa => 'HashRef', is => 'ro', );
22  
23  
24 sub _calc_site_conf
25 27 ▶{
Subroutine _calc_site_conf: called CC=1 SCAR=0.0
26 27 my ( $self, $args ) = @_;
27  
28 27 my $config = $self->config;
29  
30 27 return $config->{sites}->{ $config->{default_site} };
31 }
32  
33 sub _calc_sect_name
34 15 ▶{
Subroutine _calc_sect_name: called CC=5 SCAR=16.4
35 15 my ( $self, $args, $sections ) = @_;
36  
37 15 my $bn = $args->{basename};
38  
39 15 my $sect_name = $args->{section};
40  
41 15 ▶ if ( !defined($sect_name) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sect_name) 13 2 15
42 {
43 13 ▶ if ( $args->{is_dir} )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'is_dir'}) { } 4 9 13
44 {
45 4 $sect_name = $self->_calc_site_conf($args)->{dirs_section};
46 }
47 else
48 {
49 $sect_name = (
50 first
51 19 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 19 my $re = $sections->{$_}->{basename_re};
53 19 $bn =~ /$re/;
54 9 } ( keys(%$sections) )
55 );
56 }
57 }
58  
59 15 ▶ if ( !defined($sect_name) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sect_name) 0 15 15
60 {
61 0 Carp::confess("Unknown section for basename '$bn'");
62 }
63  
64 15 ▶ if ( !exists( $sections->{$sect_name} ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sections->{$sect_name}) 0 15 15
65 {
66 0 Carp::confess("Section '$sect_name' does not exist.");
67 }
68  
69 15 return $sect_name;
70 }
71  
72 sub _calc_target_dir
73 8 ▶{
Subroutine _calc_target_dir: called CC=2 SCAR=6.9
74 8 my ( $self, $args ) = @_;
75  
76 8 ▶ if ( defined( $args->{target_dir} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{'target_dir'}) { } 1 7 8
77 {
78 1 return $args->{target_dir};
79 }
80 else
81 {
82 7 my $sections = $self->_calc_site_conf($args)->{sections};
83  
84 7 my $sect_name = $self->_calc_sect_name( $args, $sections );
85  
86 7 return $sections->{$sect_name}->{target_dir};
87 }
88 }
89  
90 sub _calc_overrides
91 8 ▶{
Subroutine _calc_overrides: called CC=2 SCAR=6.9
92 8 my ( $self, $args ) = @_;
93  
94 8 my $sections = $self->_calc_site_conf($args)->{sections};
95  
96 8 my $sect_name = $self->_calc_sect_name( $args, $sections );
97  
98 8 ▶ return ( $sections->{$sect_name}->{overrides} || +{} );
Condition100%2/2
$sections->{$sect_name}{'overrides'} || {}
l!l
17
MC/DC100%1/1
$sections->{$sect_name}{'overrides'} || {}
$sections->{$sect_name}{'overrides'}
Truth table100%2/2
A
A= $sections->{$sect_name}{'overrides'}
Aresult
11
00
99 }
100  
101 sub _perform_upload_generic
102 8 ▶{
Subroutine _perform_upload_generic: called CC=5 SCAR=16.2
103 8 my ( $self, $is_dir, $args ) = @_;
104  
105 my $filenames = $args->{filenames}
106 8 ▶ or Carp::confess("Missing argument 'filenames'");
Branch: 1 branch
BranchTrueFalseTotal
my $filenames = $args->{"filenames"} or Carp::confess("Missing argument 'filenames'") 8 0 8
107  
108 8 ▶ if ( @$filenames != 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@$filenames != 1) 0 8 8
109 {
110 0 Carp::confess("More than one file passed to 'filenames'");
111 }
112  
113 8 my $site_conf = $self->_calc_site_conf($args);
114  
115 my $backend = App::Sky::Module->new(
116 {
117 base_upload_cmd => $site_conf->{base_upload_cmd},
118 dest_upload_prefix => $site_conf->{dest_upload_prefix},
119 dest_upload_url_prefix => $site_conf->{dest_upload_url_prefix},
120 }
121 8 );
122  
123 8 my $fn = $filenames->[0];
124 8 my $bn = basename($fn);
125  
126 8 ▶ my @dir = ( $is_dir ? ( is_dir => 1 ) : () );
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 2 6 8
127  
128 8 my $fileargs = {
129 %$args,
130 basename => $bn,
131 @dir,
132 };
133 return $backend->get_upload_results(
134 {
135 overrides => $self->_calc_overrides( $fileargs, ),
136 filenames => (
137 $is_dir
138 8 ▶ ? [ map { my $s = $_; $s =~ s#/+\z##ms; $s } @$filenames ]
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 2 6 8
139 : $filenames,
140 ),
141 target_dir => $self->_calc_target_dir( $fileargs, ),
142 @dir,
143 }
144 );
145  
146 }
147  
148  
149 sub get_upload_results
150 6 ▶{
Subroutine get_upload_results: called CC=1 SCAR=0.0
Pod documented
151 6 my ( $self, $args ) = @_;
152  
153 6 return $self->_perform_upload_generic( 0, $args );
154 }
155  
156  
157 sub get_recursive_upload_results
158 2 ▶{
Subroutine get_recursive_upload_results: called CC=1 SCAR=0.0
Pod documented
159 2 my ( $self, $args ) = @_;
160  
161 2 return $self->_perform_upload_generic( 1, $args );
162 }
163  
164 3 1;
165  
166 __END__
« Sky/Module.pm ↑ Summary Sky.pm »