blib/lib/Module/Setup/Distribute.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 100% 20 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 94.7% 18 / 19 Podpod 0.0% 0 / 14 totaltotal 86.4% 102 / 118 CC 12 SCAR 10.6
CC
12
Cov
99%
write_template
6.0
install_template
5.0
new
3.0
CRAP 2.9
« blib/lib/Module/Setup/Plugin/Additional.pm ↑ Summary blib/lib/Module/Setup/Plugin/VC/SVK.pm »
1 package Module::Setup::Distribute;
2 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 40 ▶use Fcntl qw( :mode );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 40 ▶use Module::Setup::Path::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 49 ▶ my($class, $module, %args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
12  
13 49 my @pkg = split /::/, $module;
14 49 ▶ my $target = exists $args{target} && $args{target} ? $args{target} : '.';
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'target'} && $args{'target'} ? : 47 2 49
Condition100%3/3
exists $args{"target"} and $args{"target"}
!ll&&!rl&&r
1147
MC/DC100%2/2
exists $args{"target"} and $args{"target"}
exists $args{"target"} $args{"target"}
Truth table100%3/3
A and B
A= exists $args{"target"}B= $args{"target"}
ABresult
0X0
100
111
15  
16 49 my $self = bless {
17 module => $module,
18 package => \@pkg,
19 dist_name => join('-', @pkg),
20 install_files => [],
21 }, $class;
22  
23 49 $self->{target_path} = Module::Setup::Path::Dir->new($target);
24 49 $self->{base_path} = Module::Setup::Path::Dir->new($target, $self->{dist_name});
25 49 $self->{dist_path} = Module::Setup::Path::Dir->new($target, $self->{dist_name});
26 49 $self->{module_path} = Module::Setup::Path::Dir->new(@{ $self->{package} });
27 49 $self->{additionals} = [];
28  
29 49 $self;
30 }
31  
32 1 ▶sub additionals { shift->{additionals} };
Subroutine additionals: called CC=1 SCAR=0.0
Pod undocumented
33 46 ▶sub module { shift->{module} };
Subroutine module: called CC=1 SCAR=0.0
Pod undocumented
34 46 ▶sub module_path { shift->{module_path} };
Subroutine module_path: called CC=1 SCAR=0.0
Pod undocumented
35 48 ▶sub package { shift->{package} };
Subroutine package: called CC=1 SCAR=0.0
Pod undocumented
36 60 ▶sub dist_name { shift->{dist_name} };
Subroutine dist_name: called CC=1 SCAR=0.0
Pod undocumented
37 0 ▶sub target_path { shift->{target_path} };
Subroutine target_path: not called CC=1 SCAR=6.9
Pod undocumented
38 7 ▶sub base_path { shift->{base_path} };
Subroutine base_path: called CC=1 SCAR=0.0
Pod undocumented
39 561 ▶sub dist_path { shift->{dist_path} };
Subroutine dist_path: called CC=1 SCAR=0.0
Pod undocumented
40 446 ▶sub template_vars { shift->{template_vars} };
Subroutine template_vars: called CC=1 SCAR=0.0
Pod undocumented
41 1 ▶sub install_files { shift->{install_files} };
Subroutine install_files: called CC=1 SCAR=0.0
Pod undocumented
42  
43 sub set_template_vars {
44 46 ▶ my($self, $vars) = @_;
Subroutine set_template_vars: called CC=1 SCAR=0.0
Pod undocumented
45 46 $self->{template_vars} = $vars;
46 }
47  
48 sub install_template {
49 438 ▶ my($self, $context, $path, $base_src) = @_;
Subroutine install_template: called CC=5 SCAR=16.1
Pod undocumented
50  
51 438 ▶ $base_src = $context->base_dir->flavor->template unless $base_src;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_src 428 10 438
52 438 my $src = $base_src->path_to($path);
53 438 ▶ my $template = $src->is_dir ? undef : $src->slurp;
Branch: 1 branch
BranchTrueFalseTotal
$src->is_dir ? : 8 430 438
54 438 ▶ my $options = +{
Branch: 1 branch
BranchTrueFalseTotal
$src->is_dir ? : 8 430 438
55 dist_path => ($src->is_dir ? $self->dist_path->subdir($path) : $self->dist_path->file($path)),
56 template => $template,
57 chmod => sprintf('%03o', S_IMODE(( stat $src )[2])),
58 vars => $self->template_vars,
59 content => undef,
60 };
61 438 ▶ $options->{content} = delete $options->{template} if -B $src;
Branch: 1 branch
BranchTrueFalseTotal
if -B $src 9 429 438
62 438 $self->write_template($context, $options);
63 }
64  
65 sub write_template {
66 447 ▶ my($self, $context, $options) = @_;
Subroutine write_template: called CC=6 SCAR=17.9
Pod undocumented
67 447 my $is_dir = $options->{dist_path}->is_dir;
68  
69 447 ▶ unless ($is_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_dir) 439 8 447
70 439 $context->call_trigger( template_process => $options );
71 439 ▶ $options->{template} = delete $options->{content} unless $options->{template};
Branch: 1 branch
BranchTrueFalseTotal
unless $options->{"template"} 432 7 439
72 }
73 447 ▶ $options->{dist_path} =~ s/____var-(.+?)-var____/$options->{vars}->{$1} || $options->{vars}->{config}->{$1}/eg;
Branch: 1 branch
BranchTrueFalseTotal
$options->{"vars"}{$1} or $options->{"vars"}{"config"}{$1} 1 39 40
74 447 $context->call_trigger( replace_distribute_path => $options );
75  
76 447 ▶ if ($is_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dir) { } 8 439 447
77 8 $options->{dist_path} = Module::Setup::Path::Dir->new($options->{dist_path});
78 } else {
79 439 $options->{dist_path} = Module::Setup::Path::File->new($options->{dist_path});
80 }
81  
82 447 push @{ $self->{install_files} }, $options->{dist_path};
83  
84 447 ▶ $is_dir ? $options->{dist_path}->mkpath : $context->write_file($options);
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 8 439 447
85 }
86  
87 40 1;
« blib/lib/Module/Setup/Plugin/Additional.pm ↑ Summary blib/lib/Module/Setup/Plugin/VC/SVK.pm »