| 1 | package Module::Setup::Distribute; | ||||||||||||||||||||||||||||
| 2 | 47 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 47 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 47 | ▶ | use Fcntl qw( :mode ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 47 | ▶ | use YAML (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 47 | ▶ | use Module::Setup::Path::Dir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 54 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 54 | my($class, $module, %args) = @_; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 54 | my @pkg = split /::/, $module; | |||||||||||||||||||||||||||
| 14 | 54 | ▶ | my $target = exists $args{target} && $args{target} ? $args{target} : '.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $args{"target"} and $args{"target"}
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"}
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 54 | my $self = bless { | |||||||||||||||||||||||||||
| 17 | module => $module, | ||||||||||||||||||||||||||||
| 18 | package => \@pkg, | ||||||||||||||||||||||||||||
| 19 | dist_name => join('-', @pkg), | ||||||||||||||||||||||||||||
| 20 | install_files => [], | ||||||||||||||||||||||||||||
| 21 | }, $class; | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 54 | $self->{target_path} = Module::Setup::Path::Dir->new($target); | |||||||||||||||||||||||||||
| 24 | 54 | $self->{base_path} = Module::Setup::Path::Dir->new($target, $self->{dist_name}); | |||||||||||||||||||||||||||
| 25 | 54 | $self->{dist_path} = Module::Setup::Path::Dir->new($target, $self->{dist_name}); | |||||||||||||||||||||||||||
| 26 | 54 | $self->{module_path} = Module::Setup::Path::Dir->new(@{ $self->{package} }); | |||||||||||||||||||||||||||
| 27 | 54 | $self->{additionals} = []; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 54 | $self; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | sub additionals { shift->{additionals} }; | ||||||||||||||||||||||||||
|
Subroutine
additionals: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 52 | ▶ | sub module { shift->{module} }; | ||||||||||||||||||||||||||
|
Subroutine
module: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 51 | ▶ | sub module_path { shift->{module_path} }; | ||||||||||||||||||||||||||
|
Subroutine
module_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 155 | ▶ | sub package { shift->{package} }; | ||||||||||||||||||||||||||
|
Subroutine
package: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 66 | ▶ | 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 | 612 | ▶ | sub dist_path { shift->{dist_path} }; | ||||||||||||||||||||||||||
|
Subroutine
dist_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 483 | ▶ | 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 | 51 | ▶ | sub set_template_vars { | ||||||||||||||||||||||||||
|
Subroutine
set_template_vars: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 51 | my($self, $vars) = @_; | |||||||||||||||||||||||||||
| 45 | 51 | $self->{template_vars} = $vars; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 473 | ▶ | sub install_template { | ||||||||||||||||||||||||||
|
Subroutine
install_template: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 473 | my($self, $context, $path, $base_src) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 473 | ▶ | $base_src = $context->base_dir->flavor->template unless $base_src; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 473 | my $src = $base_src->path_to($path); | |||||||||||||||||||||||||||
| 53 | 473 | ▶ | my $template = $src->is_dir ? undef : $src->slurp; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 473 | ▶ | my $options = +{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 473 | ▶ | $options->{content} = delete $options->{template} if -B $src; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 473 | $self->write_template($context, $options); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 484 | ▶ | sub write_template { | ||||||||||||||||||||||||||
|
Subroutine
write_template: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 484 | my($self, $context, $options) = @_; | |||||||||||||||||||||||||||
| 67 | 484 | my $is_dir = $options->{dist_path}->is_dir; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 484 | ▶ | unless ($is_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 476 | $context->call_trigger( template_process => $options ); | |||||||||||||||||||||||||||
| 71 | 476 | ▶ | $options->{template} = delete $options->{content} unless $options->{template}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 484 | ▶ | $options->{dist_path} =~ s/____var-(.+?)-var____/$options->{vars}->{$1} || $options->{vars}->{config}->{$1}/eg; | ||||||||||||||||||||||||||
|
Condition66%2/3
$options->{'vars'}{$1} || $options->{'vars'}{'config'}{$1}
MC/DC0%0/2
$options->{'vars'}{$1} || $options->{'vars'}{'config'}{$1}
$options->{'vars'}{$1}
$options->{'vars'}{'config'}{$1}
Truth table66%2/3
A || B
A= $options->{'vars'}{$1}B= $options->{'vars'}{'config'}{$1}
| |||||||||||||||||||||||||||||
| 74 | 484 | $context->call_trigger( replace_distribute_path => $options ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 484 | ▶ | if ($is_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 8 | $options->{dist_path} = Module::Setup::Path::Dir->new($options->{dist_path}); | |||||||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||||||||
| 79 | 476 | $options->{dist_path} = Module::Setup::Path::File->new($options->{dist_path}); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 484 | push @{ $self->{install_files} }, $options->{dist_path}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 484 | ▶ | $is_dir ? $options->{dist_path}->mkpath : $context->write_file($options); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 47 | 1; | |||||||||||||||||||||||||||