lib/Module/Provision/TraitFor/AddingFiles.pm

filter: Statementstmt 28.9% 24 / 83 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 6 / 14 Podpod 100% 4 / 4 totaltotal 24.1% 34 / 141 CC 19 SCAR 33.6
CC
19
Cov
20%
__ANON__
72.0
update_file
42.0
__ANON__
12.0
CRAP 28.8
« lib/Module/Provision/TraitFor/Rendering.pm ↑ Summary lib/Module/Provision/TraitFor/CPANDistributions.pm »
1 package Module::Provision::TraitFor::AddingFiles;
2  
3 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Class::Usul::Constants qw( EXCEPTION_CLASS OK TRUE );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Class::Usul::Functions qw( classfile throw );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Unexpected::Functions qw( Unspecified );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 requires qw( add_to_vcs appldir binsdir cmd_line_flags exec_perms expand_tuple
12 libdir loc method module_abstract next_argv output project
13 release render_template stash template_dir template_list testdir );
14  
15 # Construction
16 0 ▶around 'generate_metadata' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
17 0 my ($orig, $self, @args) = @_; my $mdf = $orig->( $self, @args );
18  
19 0 ▶ $mdf and $self->appldir->catfile( $mdf )->exists
Branch: 1 branch
BranchTrueFalseTotal
$mdf and $self->appldir->catfile($mdf)->exists and $self->add_to_vcs($mdf) 0 0 0
Condition0%0/3
$mdf and $self->appldir->catfile($mdf)->exists
!ll&&!rl&&r
000
MC/DC0%0/2
$mdf and $self->appldir->catfile($mdf)->exists
$mdf $self->appldir->catfile($mdf)->exists
Truth table0%0/3
A and B
A= $mdfB= $self->appldir->catfile($mdf)->exists
ABresult
0X0
100
111
20 and $self->add_to_vcs( $mdf );
21  
22 0 return $mdf;
23 1 };
24  
25 # Private methods
26 0 ▶my $_program_abstract = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 return $_[ 0 ]->loc( 'One-line description of the programs purpose' );
28 1 };
29  
30 0 ▶my $_get_target = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
31 0 my ($self, $dir, $f) = @_;
32  
33 0 ▶ my $car = $self->next_argv or throw Unspecified, [ 'Target' ];
Branch: 1 branch
BranchTrueFalseTotal
my $car = $self->next_argv or &throw(Unspecified(), ["Target"]) 0 0 0
34 0 ▶ my $abstract = $self->next_argv
Branch: 1 branch
BranchTrueFalseTotal
$self->method eq 'program' ? : 0 0 0
Condition0%0/3
$self->next_argv || ($self->method eq 'program' ? $self->$_program_abstract : $self->module_abstract)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->next_argv || ($self->method eq 'program' ? $self->$_program_abstract : $self->module_abstract)
$self->next_argv ($self->method eq 'program' ? $self->$_program_abstract : $self->module_abstract)
Truth table0%0/3
A || B
A= $self->next_argvB= ($self->method eq 'program' ? $self->$_program_abstract : $self->module_abstract)
ABresult
1X1
011
000
35 || ($self->method eq 'program' ? $self->$_program_abstract
36 : $self->module_abstract );
37  
38 0 $self->project; # Force evaluation of lazy attribute
39  
40 0 ▶ my $target = $self->$dir->catfile( $f ? $f->( $car ) : $car );
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 0 0 0
41  
42 0 $target->perms( $self->perms )->assert_filepath;
43  
44 0 ▶ if ($self->method eq 'module') { $self->stash->{module } = $car }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->method eq 'module') { } 0 0 0
elsif ($self->method eq 'program') { } 0 0 0
45 0 elsif ($self->method eq 'program') { $self->stash->{program_name} = $car }
46  
47 0 ▶ $self->method ne 'test' and $self->stash->{abstract} = $abstract;
Branch: 1 branch
BranchTrueFalseTotal
$self->method ne "test" and $self->stash->{"abstract"} = $abstract 0 0 0
48  
49 0 return $target;
50 1 };
51  
52 0 ▶my $_add_test_script = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
53 0 my $self = shift; my $target = $self->$_get_target( 'testdir' );
54  
55 0 ▶ $self->quiet or $self->output( 'Adding new test' );
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet or $self->output("Adding new test") 0 0 0
56 0 $target = $self->render_template( '10test_script.t', $target );
57 0 $self->add_to_vcs( $target, 'test' );
58 0 return OK;
59 1 };
60  
61 # Public methods
62 0 ▶sub module : method {
Subroutine module: not called CC=2 SCAR=17.9
Pod documented
63 0 my $self = shift; my $target = $self->$_get_target( 'libdir', \&classfile );
64  
65 0 ▶ $self->quiet or $self->output( 'Adding new module' );
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet or $self->output("Adding new module") 0 0 0
66 0 $target = $self->render_template( 'perl_module.pm', $target );
67 0 $self->add_to_vcs( $target, 'module' );
68 0 return OK;
69 }
70  
71 0 ▶sub program : method {
Subroutine program: not called CC=2 SCAR=17.9
Pod documented
72 0 my $self = shift; my $target = $self->$_get_target( 'binsdir' );
73  
74 0 ▶ $self->quiet or $self->output( 'Adding new program' );
Branch: 1 branch
BranchTrueFalseTotal
$self->quiet or $self->output("Adding new program") 0 0 0
75 0 $target = $self->render_template( 'perl_program.pl', $target );
76 0 chmod $self->exec_perms, $target->pathname;
77 0 $self->add_to_vcs( $target, 'program' );
78 0 return OK;
79 }
80  
81 0 ▶sub test : method {
Subroutine test: not called CC=2 SCAR=17.9
Pod documented
82 0 my $self = shift; my $flags = $self->cmd_line_flags; $flags->{test} = TRUE;
83  
84 0 ▶ return $flags->{release} ? $self->release : $self->$_add_test_script;
Branch: 1 branch
BranchTrueFalseTotal
$flags->{'release'} ? : 0 0 0
85 }
86  
87 0 ▶sub update_file : method {
Subroutine update_file: not called CC=6 SCAR=37.4
Pod documented
88 0 my $self = shift;
89 0 ▶ my $target = $self->next_argv or throw Unspecified, [ 'target' ];
Branch: 1 branch
BranchTrueFalseTotal
my $target = $self->next_argv or &throw(Unspecified(), ["target"]) 0 0 0
90 0 my $index = {};
91  
92 0 for my $t (map { my $k = $_->[ 0 ]; my $v = $_->[ 1 ];
93 0 $_->[ 1 ] = $v->relative( $self->appldir ); $_ }
94 0 map { my $k = $_->[ 0 ]; my $v = $_->[ 1 ];
95 0 ▶ $v->is_dir and $_->[ 1 ] = $v->catfile( $k ); $_ }
Branch: 1 branch
BranchTrueFalseTotal
$v->is_dir and $_->[1] = $v->catfile($k) 0 0 0
96 0 map { $self->expand_tuple( $_ ) } @{ $self->template_list } ) {
97 0 $index->{ $t->[ 1 ]->pathname } = $t->[ 0 ];
98 }
99  
100 0 ▶ exists $index->{ $target }
Branch: 1 branch
BranchTrueFalseTotal
exists $index->{$target} or &throw("File [_1] not in template map", [$target]) 0 0 0
101 or throw 'File [_1] not in template map', [ $target ];
102  
103 0 my $source = $self->template_dir->catfile( $index->{ $target } );
104  
105 0 ▶ $source->exists or throw 'File [_1] not found', [ $source ];
Branch: 1 branch
BranchTrueFalseTotal
$source->exists or &throw("File [_1] not found", [$source]) 0 0 0
106 0 $source->copy( $target );
107 0 return OK;
108 }
109  
110 1 1;
111  
112 __END__
« lib/Module/Provision/TraitFor/Rendering.pm ↑ Summary lib/Module/Provision/TraitFor/CPANDistributions.pm »