blib/lib/Module/Setup.pm

filter: Statementstmt 99.4% 348 / 350 Branchbran 96.1% 125 / 130 Conditioncond 100% 62 / 62 MC/DCmcdc 97.1% 34 / 35 Subroutinesub 100% 52 / 52 Podpod 0.0% 0 / 23 totaltotal 95.2% 621 / 652 CC 97 SCAR 19.1
CC
97
Cov
99%
create_flavor
18.0
run
11.0
pack_flavor
10.0
CRAP 6.7
« blib/lib/Module/Setup/Flavor/SelectVC.pm ↑ Summary blib/lib/Module/Setup/Flavor.pm »
1 package Module::Setup;
2  
3 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 our $VERSION = '0.06_01';
7  
8 40 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 40 ▶use Class::Trigger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 40 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 40 ▶use ExtUtils::MakeMaker qw(prompt);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 40 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 40 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 40 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 40 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 40 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 40 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 40 ▶use Module::Setup::Devel;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 40 ▶use Module::Setup::Distribute;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 40 ▶use Module::Setup::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 40 ▶use Module::Setup::Path::Flavor;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 40 ▶use Module::Setup::Path::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 40 our $HAS_TERM;
26  
27 241 ▶sub argv { shift->{argv} }
Subroutine argv: called CC=1 SCAR=0.0
Pod undocumented
28 139 ▶sub config { shift->{config} }
Subroutine config: called CC=1 SCAR=0.0
Pod undocumented
29 1228 ▶sub options { shift->{options} }
Subroutine options: called CC=1 SCAR=0.0
Pod undocumented
30 1825 ▶sub base_dir { shift->{base_dir} }
Subroutine base_dir: called CC=1 SCAR=0.0
Pod undocumented
31 406 ▶sub distribute { shift->{distribute} }
Subroutine distribute: called CC=1 SCAR=0.0
Pod undocumented
32 5 ▶sub plugins_stash { shift->{plugins_stash} }
Subroutine plugins_stash: called CC=1 SCAR=0.0
Pod undocumented
33  
34 sub new {
35 110 ▶ my($class, %args) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
36  
37 110 ▶ $args{options} ||= +{};
Condition100%2/2
$args{"options"} ||= {}
l!l
9218
MC/DC100%1/1
$args{"options"} ||= {}
$args{"options"}
Truth table100%2/2
A
A= $args{"options"}
Aresult
11
00
38 110 ▶ $args{argv} ||= +[];
Condition100%2/2
$args{"argv"} ||= []
l!l
9218
MC/DC100%1/1
$args{"argv"} ||= []
$args{"argv"}
Truth table100%2/2
A
A= $args{"argv"}
Aresult
11
00
39 110 $args{_current_dir} = Cwd::getcwd;
40  
41 110 my $self = bless { %args }, $class;
42 110 $self->{_current_dir} = Cwd::getcwd;
43 110 $self->{plugins_stash} = +{};
44  
45 110 $self;
46 }
47  
48 sub DESTROY {
49 84 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=6.9
50 84 ▶ chdir $self->{_current_dir} unless $self->{_current_dir} eq Cwd::getcwd;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_current_dir"} eq Cwd::getcwd() 5 79 84
51 }
52  
53 sub _setup_options_pod2usage {
54 3 ▶ pod2usage(1);
Subroutine _setup_options_pod2usage: called CC=1 SCAR=0.0
55 }
56 sub _setup_options_version {
57 1 ▶ print "module-setup v$VERSION\n";
Subroutine _setup_options_version: called CC=1 SCAR=0.0
58 1 exit 1;
59 }
60  
61 sub setup_options {
62 17 ▶ my($self, %args) = @_;
Subroutine setup_options: called CC=3 SCAR=11.0
Pod undocumented
63 17 $Module::Setup::HAS_TERM = 1;
64  
65 17 ▶ _setup_options_pod2usage unless @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 1 16 17
66  
67 17 my $options = {};
68 GetOptions(
69 'init' => \($options->{init}),
70 'pack' => \($options->{pack}),
71 'direct' => \($options->{direct}),
72 'flavor|flavour=s' => \($options->{flavor}),
73 'flavor-class|flavour-class=s' => \($options->{flavor_class}),
74 'additional=s' => \($options->{additional}),
75 'without-additional' => \($options->{without_additional}),
76 'executable' => \($options->{executable}),
77 'plugin=s@' => \($options->{plugins}),
78 'target' => \($options->{target}),
79 'module-setup-dir' => \($options->{module_setup_dir}),
80 'devel' => \($options->{devel}),
81 17 ▶ 'test' => \($options->{test}),
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("init", \$options->{"init"}, "pack", \$options->{"pack"}, "direct", \$options->{"direct"}, "flavor|flavour=s", \$options->{"flavor"}, "flavor-class|flavour-class=s", \$options->{"flavor_class"}, "additional=s", \$options->{"additional"}, "without-additional", \$options->{"without_additional"}, "executable", \$options->{"executable"}, "plugin=s\@", \$options->{"plugins"}, "target", \$options->{"target"}, "module-setup-dir", \$options->{"module_setup_dir"}, "devel", \$options->{"devel"}, "test", \$options->{"test"}, "version", \&Module::Setup::_setup_options_version, "help", \&Module::Setup::_setup_options_pod2usage) or _setup_options_pod2usage() 1 16 17
82 version => \&_setup_options_version,
83 help => \&_setup_options_pod2usage,
84 ) or _setup_options_pod2usage;
85  
86 17 $self->{options} = $options;
87 17 $self->{argv} = [ @ARGV ];
88 17 $self;
89 }
90  
91  
92 sub _clear_triggers {
93 130 ▶ my $self = shift;
Subroutine _clear_triggers: called CC=1 SCAR=0.0
94 # reset triggers # this is bad hack
95 130 delete $self->{__triggers};
96 130 delete $self->{_class_trigger_results};
97 }
98  
99 sub _load_argv {
100 157 ▶ my($self, $name, $default) = @_;
Subroutine _load_argv: called CC=5 SCAR=16.1
101  
102 157 ▶ $self->options->{$name} = @{ $self->argv } ? shift @{ $self->argv } : undef;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->argv;} ? : 84 73 157
103 157 ▶ if (!$self->options->{$name} && defined $default) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->options->{$name} and defined $default) 75 82 157
Condition100%3/3
not $self->options->{$name} and defined $default
!ll&&!rl&&r
81175
MC/DC100%2/2
not $self->options->{$name} and defined $default
not $self->options->{$name} defined $default
Truth table100%3/3
not(A) and B
A= not $self->options->{$name}B= defined $default
ABresult
0X0
100
111
104 75 ▶ $self->options->{$name} = ref($default) eq 'CODE' ? $default->() : $default;
Branch: 1 branch
BranchTrueFalseTotal
ref $default eq 'CODE' ? : 57 18 75
105 }
106 157 $self->options->{$name};
107 }
108 sub _load_argv_module {
109 62 ▶ my $self = shift;
Subroutine _load_argv_module: called CC=2 SCAR=6.9
110 62 $self->_load_argv( module => '' );
111 62 ▶ Carp::croak "module name is required" unless $self->options->{module};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->options->{"module"} 1 61 62
112 61 $self->options->{module};
113 }
114 sub _load_argv_flavor {
115 61 ▶ my $self = shift;
Subroutine _load_argv_flavor: called CC=2 SCAR=6.9
116 61 ▶ $self->_load_argv( flavor => sub { $self->select_flavor } );
Subroutine __ANON__: called CC=1 SCAR=0.0
117 61 ▶ Carp::croak "flavor name is required" unless $self->options->{flavor};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->options->{"flavor"} 1 60 61
118 60 $self->options->{flavor};
119 }
120  
121 sub setup_base_dir {
122 95 ▶ my $self = shift;
Subroutine setup_base_dir: called CC=6 SCAR=17.9
Pod undocumented
123  
124 95 my $path;
125 95 ▶ if ($self->options->{direct}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{'direct'}) { } 1 94 95
126 1 $path = File::Temp->newdir;
127 } else {
128 94 ▶ $path = $self->options->{module_setup_dir} || $ENV{MODULE_SETUP_DIR} || Path::Class::Dir->new(File::HomeDir->my_home, '.module-setup');
Condition100%6/6
$self->options->{'module_setup_dir'} || $ENV{'MODULE_SETUP_DIR'} || 'Path::Class::Dir'->new('File::HomeDir'->my_home, '.module-setup')
l!l&&r!l&&!r
9211
$self->options->{"module_setup_dir"} or $ENV{"MODULE_SETUP_DIR"}
l!l&&r!l&&!r
9112
MC/DC100%3/3
$self->options->{'module_setup_dir'} || $ENV{'MODULE_SETUP_DIR'} || 'Path::Class::Dir'->new('File::HomeDir'->my_home, '.module-setup')
$self->options->{"module_setup_dir"} $ENV{"MODULE_SETUP_DIR"} 'Path::Class::Dir'->new('File::HomeDir'->my_home, '.module-setup')
Truth table100%4/4
A or B || C
A= $self->options->{"module_setup_dir"}B= $ENV{"MODULE_SETUP_DIR"}C= 'Path::Class::Dir'->new('File::HomeDir'->my_home, '.module-setup')
ABCresult
1XX1
01X1
0011
0000
129 }
130 95 ▶ die 'module_setup directory was not able to be discovered.' unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 1 94 95
131  
132 94 $self->{base_dir} = Module::Setup::Path->new($path);
133 94 ▶ $self->base_dir->init_directories unless $self->base_dir->is_initialized;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->base_dir->is_initialized 42 52 94
134 }
135  
136 sub run {
137 91 ▶ my $self = shift;
Subroutine run: called CC=11 SCAR=24.0
Pod undocumented
138 91 my $options = $self->options;
139 91 $self->_clear_triggers;
140  
141 91 ▶ $options->{flavor_class} ||= 'Default';
Condition100%2/2
$options->{"flavor_class"} ||= "Default"
l!l
2566
MC/DC100%1/1
$options->{"flavor_class"} ||= "Default"
$options->{"flavor_class"}
Truth table100%2/2
A
A= $options->{"flavor_class"}
Aresult
11
00
142 91 ▶ return Module::Setup::Devel->new($self)->run if $options->{devel};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"devel"} 0 91 91
143  
144 91 $self->setup_base_dir;
145  
146 91 ▶ if ($options->{init} || (!$options->{pack} && $options->{additional})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"init"} or not $options->{"pack"} and $options->{"additional"}) 29 62 91
Condition100%6/6
$options->{"init"} or not $options->{"pack"} and $options->{"additional"}
l!l&&r!l&&!r
24562
not $options->{"pack"} and $options->{"additional"}
!ll&&!rl&&r
11515
MC/DC66%2/3
$options->{"init"} or not $options->{"pack"} and $options->{"additional"}
$options->{"init"} not $options->{"pack"} $options->{"additional"}
Truth table75%3/4
A or not(B) and C
A= $options->{"init"}B= not $options->{"pack"}C= $options->{"additional"}
ABCresult
1XX1
0111
00X0
0100
147 29 $self->_load_argv( flavor => 'default' );
148 29 return $self->create_flavor;
149 }
150  
151 62 $self->_load_argv_module;
152 61 $self->_load_argv_flavor;
153 60 $self->base_dir->set_flavor($options->{flavor});
154  
155 60 ▶ if ($options->{additional} && !-d $self->base_dir->flavor->additional->path_to($options->{additional})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"additional"} and not -d $self->base_dir->flavor->additional->path_to($options->{"additional"})) 1 59 60
Condition100%3/3
$options->{"additional"} and not -d $self->base_dir->flavor->additional->path_to($options->{"additional"})
!ll&&!rl&&r
5721
MC/DC100%2/2
$options->{"additional"} and not -d $self->base_dir->flavor->additional->path_to($options->{"additional"})
$options->{"additional"} not -d $self->base_dir->flavor->additional->path_to($options->{"additional"})
Truth table100%3/3
A and not(B)
A= $options->{"additional"}B= not -d $self->base_dir->flavor->additional->path_to($options->{"additional"})
ABresult
0X0
100
111
156 1 Carp::croak "additional template is no exist: $options->{additional}";
157 }
158  
159 59 ▶ return $self->pack_flavor if $options->{pack};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"pack"} 10 49 59
160  
161 49 ▶ unless ($self->base_dir->flavor->is_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->base_dir->flavor->is_dir) 20 29 49
162 20 ▶ return unless $self->create_flavor;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->create_flavor 1 17 18
163 }
164  
165 46 $self->load_config;
166 46 $self->load_plugins;
167  
168 # create skeleton
169 46 $self->create_skeleton;
170 46 $self->call_trigger( 'after_create_skeleton' );
171  
172 # test
173 46 chdir $self->distribute->dist_path;
174 46 $self->call_trigger( 'check_skeleton_directory' );
175 39 $self->call_trigger( 'finalize_create_skeleton' );
176 39 chdir $self->{_current_dir};
177  
178 39 $self->call_trigger( 'finish_of_run' );
179 37 $self;
180 }
181  
182  
183 sub load_config {
184 46 ▶ my $self = shift;
Subroutine load_config: called CC=2 SCAR=6.9
Pod undocumented
185 46 my $options = $self->options;
186  
187 46 ▶ my $option_plugins = delete $options->{plugins} || [];
Condition100%2/2
delete $options->{'plugins'} || []
l!l
1036
MC/DC100%1/1
delete $options->{'plugins'} || []
delete $options->{'plugins'}
Truth table100%2/2
A
A= delete $options->{'plugins'}
Aresult
11
00
188 46 my $config = $self->base_dir->flavor->config->load;
189 $config = +{
190 plugins => [],
191 46 %{ $config },
192 46 %{ $options },
193 };
194 46 push @{ $config->{plugins} }, @{ $option_plugins };
195  
196 46 $self->{config} = $config;
197 }
198  
199 sub plugin_collect {
200 86 ▶ my $self = shift;
Subroutine plugin_collect: called CC=3 SCAR=11.3
Pod undocumented
201  
202 86 my %loaded_local_plugin;
203 86 for my $local_plugin ( $self->base_dir->global_plugins->collect, $self->base_dir->flavor->plugins->collect ) {
204 1 $local_plugin->require;
205 1 ▶ if ($local_plugin->package->isa('Module::Setup::Plugin')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_plugin->package->isa("Module::Setup::Plugin")) 0 1 1
206 0 $loaded_local_plugin{$local_plugin->package} = $local_plugin;
207 }
208 }
209 86 %loaded_local_plugin;
210 }
211  
212 sub load_plugins {
213 86 ▶ my $self = shift;
Subroutine load_plugins: called CC=8 SCAR=20.8
Pod undocumented
214  
215 86 my %loaded_local_plugin = $self->plugin_collect;
216  
217 86 ▶ $self->{loaded_plugin} ||= +{};
Condition100%2/2
$self->{"loaded_plugin"} ||= {}
l!l
1769
MC/DC100%1/1
$self->{"loaded_plugin"} ||= {}
$self->{"loaded_plugin"}
Truth table100%2/2
A
A= $self->{"loaded_plugin"}
Aresult
11
00
218 86 for my $plugin (@{ $self->config->{plugins} }) {
219 320 my $pkg;
220 320 my $config = +{};
221 320 ▶ if (ref($plugin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plugin) { } 4 316 320
222 4 ▶ if (ref($plugin) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $plugin eq 'HASH') { } 2 2 4
223 2 $pkg = $plugin->{module};
224 2 $config = $plugin->{config};
225 } else {
226 2 next;
227 }
228 } else {
229 316 $pkg = $plugin;
230 }
231 318 ▶ $pkg = "Module::Setup::Plugin::$pkg" unless $pkg =~ s/^\+//;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg =~ s/^\+// 310 8 318
232  
233 318 ▶ unless ($loaded_local_plugin{$pkg}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($loaded_local_plugin{$pkg}) 318 0 318
234 318 eval "require $pkg"; ## no critic
235 318 ▶ Carp::croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 317 318
236 }
237 317 $self->{loaded_plugin}->{$pkg} = $pkg->new( context => $self, config => $config );
238 }
239 }
240  
241 sub write_file {
242 806 ▶ my($self, $opts) = @_;
Subroutine write_file: called CC=5 SCAR=16.1
Pod undocumented
243 806 my $path = $opts->{dist_path};
244  
245 806 ▶ if (-e $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path) { } 58 748 806
246 58 my $ans = $self->dialog("$path exists. Override? [yN] ", 'n');
247 58 ▶ return if $ans !~ /[Yy]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ans =~ /[Yy]/ 46 12 58
248 } else {
249 748 $path->dir->mkpath;
250 }
251  
252 760 my $template;
253 760 ▶ if ($opts->{is_binary}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'is_binary'}) { } 1 759 760
254 1 $template = pack 'H*', $opts->{template};
255 } else {
256 759 $template = $opts->{template};
257 }
258  
259 760 $self->log("Creating $path");
260 760 my $out = $path->openw;
261 760 $out->print($template);
262 760 $out->close;
263  
264 760 ▶ chmod oct($opts->{chmod}), $path if $opts->{chmod};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"chmod"} 417 343 760
265 }
266  
267 sub install_flavor {
268 389 ▶ my($self, $tmpl) = @_;
Subroutine install_flavor: called CC=9 SCAR=22.0
Pod undocumented
269  
270 389 my $flavor = $self->base_dir->flavor;
271 389 my $template_path = $flavor->template;
272 389 ▶ if (exists $tmpl->{additional}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpl->{"additional"}) 21 368 389
273 21 $template_path = Module::Setup::Path::Template->new($flavor->additional->path, $tmpl->{additional});
274 21 $template_path->path->mkpath;
275 }
276  
277 389 my $path;
278 389 ▶ if (exists $tmpl->{file} && $tmpl->{file}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $tmpl->{'file'} and $tmpl->{'file'}) { } 366 23 389
elsif (exists $tmpl->{'dir'} and $tmpl->{'dir'}) { } 9 14 23
elsif (exists $tmpl->{'plugin'} and $tmpl->{'plugin'} and not exists $tmpl->{'additional'}) { } 2 12 14
Condition100%3/3
exists $tmpl->{"file"} and $tmpl->{"file"}
!ll&&!rl&&r
221366
MC/DC100%2/2
exists $tmpl->{"file"} and $tmpl->{"file"}
exists $tmpl->{"file"} $tmpl->{"file"}
Truth table100%3/3
A and B
A= exists $tmpl->{"file"}B= $tmpl->{"file"}
ABresult
0X0
100
111
279 366 $path = $template_path->path_to(split '/', $tmpl->{file});
280 ▶ } elsif (exists $tmpl->{dir} && $tmpl->{dir}) {
Condition100%3/3
exists $tmpl->{"dir"} and $tmpl->{"dir"}
!ll&&!rl&&r
1319
MC/DC100%2/2
exists $tmpl->{"dir"} and $tmpl->{"dir"}
exists $tmpl->{"dir"} $tmpl->{"dir"}
Truth table100%3/3
A and B
A= exists $tmpl->{"dir"}B= $tmpl->{"dir"}
ABresult
0X0
100
111
281 9 return Module::Setup::Path::Dir->new( $template_path->path, split('/', $tmpl->{dir}) )->mkpath;
282 ▶ } elsif (exists $tmpl->{plugin} && $tmpl->{plugin} && !exists $tmpl->{additional}) {
Condition100%6/6
exists $tmpl->{"plugin"} and $tmpl->{"plugin"} and not exists $tmpl->{"additional"}
!ll&&!rl&&r
572
exists $tmpl->{"plugin"} and $tmpl->{"plugin"}
!ll&&!rl&&r
419
MC/DC100%3/3
exists $tmpl->{"plugin"} and $tmpl->{"plugin"} and not exists $tmpl->{"additional"}
exists $tmpl->{"plugin"} $tmpl->{"plugin"} not exists $tmpl->{"additional"}
Truth table100%4/4
A and B and not(C)
A= exists $tmpl->{"plugin"}B= $tmpl->{"plugin"}C= not exists $tmpl->{"additional"}
ABCresult
0XX0
10X0
1100
1111
283 2 $path = $flavor->plugins->path_to(split '/', $tmpl->{plugin});
284 } else {
285 12 return;
286 }
287  
288 $self->write_file(+{
289 dist_path => $path,
290 368 %{ $tmpl },
291 });
292 }
293  
294 sub _load_flavor_class {
295 49 ▶ my($self, $class) = @_;
Subroutine _load_flavor_class: called CC=3 SCAR=11.0
296 49 ▶ $class = "Module::Setup::Flavor::$class" unless $class =~ s/^\+//;
Branch: 1 branch
BranchTrueFalseTotal
unless $class =~ s/^\+// 33 16 49
297 49 ▶ eval " require $class "; Carp::croak $@ if $@; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 48 49
298 48 $class;
299 }
300  
301 sub create_flavor {
302 49 ▶ my $self = shift;
Subroutine create_flavor: called CC=18 SCAR=28.9
Pod undocumented
303  
304 49 my $options = $self->options;
305 49 my $name = $options->{flavor};
306 49 my $flavor_class = $self->_load_flavor_class($options->{flavor_class});
307  
308 48 $self->base_dir->set_flavor($name);
309 48 ▶ Carp::croak "create flavor: $name exists " if $self->base_dir->flavor->is_exists && !exists $options->{additional};
Branch: 1 branch
BranchTrueFalseTotal
if $self->base_dir->flavor->is_exists and not exists $options->{"additional"} 1 47 48
Condition100%3/3
$self->base_dir->flavor->is_exists and not exists $options->{"additional"}
!ll&&!rl&&r
4251
MC/DC100%2/2
$self->base_dir->flavor->is_exists and not exists $options->{"additional"}
$self->base_dir->flavor->is_exists not exists $options->{"additional"}
Truth table100%3/3
A and not(B)
A= $self->base_dir->flavor->is_existsB= not exists $options->{"additional"}
ABresult
0X0
100
111
310 47 my $flavor = $flavor_class->new;
311 47 ▶ return unless $flavor->setup_flavor($self);
Branch: 1 branch
BranchTrueFalseTotal
unless $flavor->setup_flavor($self) 2 45 47
312  
313 45 my @template = $flavor->loader;
314 45 my $config = +{};
315 45 my $additional_config = +{};
316 45 ▶ if ($options->{additional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"additional"}) 5 40 45
317 5 $additional_config = $self->base_dir->flavor->additional->config->load;
318 }
319 45 for my $tmpl (@template) {
320 424 ▶ if (exists $tmpl->{config} && ref($tmpl->{config}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpl->{'config'} and ref $tmpl->{'config'} eq 'HASH') { } 35 389 424
Condition100%3/3
exists $tmpl->{"config"} and ref $tmpl->{"config"} eq "HASH"
!ll&&!rl&&r
388135
MC/DC100%2/2
exists $tmpl->{"config"} and ref $tmpl->{"config"} eq "HASH"
exists $tmpl->{"config"} ref $tmpl->{"config"} eq "HASH"
Truth table100%3/3
A and B
A= exists $tmpl->{"config"}B= ref $tmpl->{"config"} eq "HASH"
ABresult
0X0
100
111
321 35 $config = $tmpl->{config};
322 } else {
323 389 my $additional;
324 389 ▶ if (exists $tmpl->{additional}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $tmpl->{'additional'}) { } 6 383 389
elsif ($options->{'additional'}) { } 15 368 383
325 6 $additional = $tmpl->{additional};
326 } elsif ($options->{additional}) {
327 15 $additional = $options->{additional};
328 }
329 389 ▶ local $tmpl->{additional} = $additional if $additional; ## no critic;
Branch: 1 branch
BranchTrueFalseTotal
if $additional 21 368 389
330 389 ▶ if ($additional) {
Branch: 1 branch
BranchTrueFalseTotal
if ($additional) 21 368 389
331 21 $additional_config->{$additional} = +{
332 class => $flavor_class,
333 };
334 }
335 389 $self->install_flavor($tmpl);
336 }
337 }
338 45 $config->{class} = $flavor_class;
339  
340 45 $self->base_dir->flavor->additional->path->mkpath;
341 45 $self->base_dir->flavor->additional->config->dump($additional_config);
342  
343 45 ▶ if ($options->{additional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"additional"}) 5 40 45
344 5 $flavor->setup_additional($self, $config);
345 5 return 1;
346 }
347  
348 40 $self->base_dir->flavor->plugins->path->mkpath;
349 40 $self->base_dir->flavor->template->path->mkpath;
350  
351 40 ▶ if (exists $options->{plugins} && $options->{plugins} && @{ $options->{plugins} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"plugins"} and $options->{"plugins"} and @{$options->{"plugins"};}) 6 34 40
Condition100%6/6
exists $options->{"plugins"} and $options->{"plugins"} and @{$options->{"plugins"};}
!ll&&!rl&&r
3316
exists $options->{"plugins"} and $options->{"plugins"}
!ll&&!rl&&r
3217
MC/DC100%3/3
exists $options->{"plugins"} and $options->{"plugins"} and @{$options->{"plugins"};}
exists $options->{"plugins"} $options->{"plugins"} @{$options->{"plugins"};}
Truth table100%4/4
A and B and C
A= exists $options->{"plugins"}B= $options->{"plugins"}C= @{$options->{"plugins"};}
ABCresult
0XX0
10X0
1100
1111
352 6 ▶ $config->{plugins} ||= [];
Condition100%2/2
$config->{"plugins"} ||= []
l!l
51
MC/DC100%1/1
$config->{"plugins"} ||= []
$config->{"plugins"}
Truth table100%2/2
A
A= $config->{"plugins"}
Aresult
11
00
353 6 push @{ $config->{plugins} }, @{ delete $options->{plugins} };
354 }
355 40 ▶ $config->{plugins} ||= [];
Condition100%2/2
$config->{"plugins"} ||= []
l!l
364
MC/DC100%1/1
$config->{"plugins"} ||= []
$config->{"plugins"}
Truth table100%2/2
A
A= $config->{"plugins"}
Aresult
11
00
356  
357 40 $flavor->setup_config($self, $config);
358  
359 # load plugins
360 local $self->{config} = +{
361 40 %{ $config },
362 40 %{ $options },
363 plugins => $config->{plugins},
364 40 };
365 40 $self->load_plugins;
366  
367 39 $self->call_trigger( before_dump_config => $config );
368  
369 39 $self->_clear_triggers;
370  
371 39 $self->base_dir->flavor->config->dump($config);
372 }
373  
374 sub create_skeleton {
375 46 ▶ my $self = shift;
Subroutine create_skeleton: called CC=2 SCAR=6.9
Pod undocumented
376 46 my $config = $self->config;
377  
378 $self->{distribute} = Module::Setup::Distribute->new(
379 $config->{module},
380 target => $config->{target},
381 46 );
382 46 $self->call_trigger( 'after_setup_module_attribute' );
383 46 $self->distribute->dist_path->mkpath;
384  
385 my $template_vars = {
386 module => $self->distribute->module,
387 dist => $self->distribute->dist_name,
388 module_path => $self->distribute->module_path,
389 46 module_unix_path => join('/', @{ $self->distribute->package }),
390 config => $config,
391 distribute => $self->distribute,
392 localtime => scalar localtime,
393 };
394 46 $self->call_trigger( after_setup_template_vars => $template_vars);
395 46 $self->{distribute}->set_template_vars($template_vars);
396  
397 46 for my $path ($self->base_dir->flavor->template->find_files) {
398 428 $self->{distribute}->install_template($self, $path);
399 }
400 46 $self->call_trigger( 'append_template_file' );
401  
402 46 return $template_vars;
403 }
404  
405 sub _collect_flavor_files {
406 24 ▶ my($self, $template, $path_name, $type) = @_;
Subroutine _collect_flavor_files: called CC=6 SCAR=17.9
407  
408 24 my $base_path = $type->path;
409 24 for my $file ($type->find_files) {
410 99 ▶ my @path = $file->is_dir ? $file->dir_list : ($file->dir->dir_list, $file->basename);
Branch: 1 branch
BranchTrueFalseTotal
$file->is_dir ? : 5 94 99
411 99 ▶ while ($path[0] eq '.') { shift @path };
Branch: 1 branch
BranchTrueFalseTotal
if ($path[0] eq ".") 46 99 145
412  
413 99 ▶ if ($file->is_dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->is_dir) { } 5 94 99
414 5 push @{ $template }, +{
415 dir => join('/', @path),
416 };
417 } else {
418 94 my $body = $type->path_to($file)->slurp;
419 94 my $tmpl = +{
420 $path_name => join('/', @path),
421 template => $body,
422 };
423 94 ▶ if (-B $type->path_to($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-B $type->path_to($file)) 1 93 94
424 1 $tmpl->{template} = unpack 'H*', $body;
425 1 $tmpl->{is_binary} = 1;
426 }
427 94 push @{ $template }, $tmpl;
428 }
429 }
430 }
431  
432 sub pack_flavor {
433 10 ▶ my $self = shift;
Subroutine pack_flavor: called CC=10 SCAR=23.0
Pod undocumented
434 10 my $config = $self->options;
435 10 my $module = $config->{module};
436 10 my $flavor = $config->{flavor};
437  
438 10 my $template = [];
439 10 ▶ my $flavor_dir = exists $config->{flavor_dir} ? Module::Setup::Path::Flavor->new( $config->{flavor_dir} ) : $self->base_dir->flavor;
Branch: 1 branch
BranchTrueFalseTotal
exists $config->{'flavor_dir'} ? : 0 10 10
440 10 $self->_collect_flavor_files($template, file => $flavor_dir->template);
441 10 $self->_collect_flavor_files($template, plugin => $flavor_dir->plugins);
442 10 push @{ $template }, +{
443 config => YAML::LoadFile($flavor_dir->config->path),
444 };
445  
446 10 ▶ unless ($config->{without_additional}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($config->{"without_additional"}) 9 1 10
447 9 ▶ $template = [] if $config->{additional};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"additional"} 2 7 9
448 9 for my $additional ( $flavor_dir->additional->path->children ) {
449 18 ▶ next unless $additional->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $additional->is_dir 12 6 18
450 6 my $name = $additional->dir_list(-1);
451 6 ▶ next if $config->{additional} && $name ne $config->{additional};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"additional"} and $name ne $config->{"additional"} 2 4 6
Condition100%3/3
$config->{"additional"} and $name ne $config->{"additional"}
!ll&&!rl&&r
222
MC/DC100%2/2
$config->{"additional"} and $name ne $config->{"additional"}
$config->{"additional"} $name ne $config->{"additional"}
Truth table100%3/3
A and B
A= $config->{"additional"}B= $name ne $config->{"additional"}
ABresult
0X0
100
111
452 4 my $base_path = Module::Setup::Path::Template->new($flavor_dir->additional->path, $name);
453  
454 4 my $templates = [];
455 4 $self->_collect_flavor_files($templates, file => $base_path);
456 4 ▶ if ($config->{additional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{'additional'}) { } 2 2 4
457 2 push @{ $template }, @{ $templates };
458 } else {
459 2 push @{ $template }, map { $_->{additional} = $name; $_ } @{ $templates };
460 }
461 }
462 }
463  
464 10 my $executable_code = '';
465 10 ▶ if ($config->{executable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"executable"}) 0 10 10
466 0 $executable_code = <<EXECUTABLE__;
467 #!/bin/env perl
468 package main;
469 use strict;
470 use warnings;
471 use Module::Setup;
472  
473 my \$msetup = Module::Setup->new;
474 \$msetup->setup_options;
475 \$msetup->options->{direct} = 1;
476 \$msetup->options->{flavor_class} = '+$config->{module}';
477 {
478 no warnings 'redefine';
479 *Module::Setup::_load_flavor_class = sub { '$config->{module}' };
480 \$msetup->run;
481 }
482 EXECUTABLE__
483 }
484  
485 10 my $eq = '=';
486 10 my $yaml = YAML::Dump(@{ $template });
487 10 $self->stdout(<<FLAVOR__);
488 $executable_code
489 package $module;
490 use strict;
491 use warnings;
492 use base 'Module::Setup::Flavor';
493 1;
494  
495 ${eq}head1
496  
497 $module - pack from $flavor
498  
499 ${eq}head1 SYNOPSIS
500  
501 $ module-setup --init --flavor-class=+$module new_flavor
502  
503 ${eq}cut
504  
505 \__DATA__
506  
507 $yaml
508 FLAVOR__
509 }
510  
511 sub select_flavor {
512 53 ▶ my $self = shift;
Subroutine select_flavor: called CC=8 SCAR=20.8
Pod undocumented
513 53 ▶ return 'default' if $self->options->{direct};
Branch: 1 branch
BranchTrueFalseTotal
if $self->options->{"direct"} 1 52 53
514 52 ▶ return 'default' if $self->base_dir->flavors->path->children == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->base_dir->flavors->path->children == 0 18 34 52
515  
516 34 my @flavors;
517 34 for my $flavor ( $self->base_dir->flavors->path->children ) {
518 37 ▶ next unless $flavor->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $flavor->is_dir 1 36 37
519 36 my $name = $flavor->dir_list(-1);
520 36 ▶ ($name eq 'default') ? unshift @flavors, $name : push @flavors, $name;
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'default' ? : 34 2 36
521 }
522 34 ▶ return $flavors[0] if @flavors == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @flavors == 1 33 1 34
523  
524 1 my $num = 1;
525 1 my $message;
526 1 for my $flavor (@flavors) {
527 3 $message .= sprintf "[%d]: %s\n", $num++, $flavor;
528 }
529  
530 1 my $selected;
531 $self->dialog( "${message}Select flavor:", 1, sub {
532 5 ▶ my($self, $ret) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
533 5 ▶ return unless $ret =~ /^[0-9]+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ret =~ /^[0-9]+$/ 3 2 5
534 2 $selected = $flavors[ $ret - 1 ];
535 1 } );
536 1 $self->log("You chose flavor: $selected");
537 1 return $selected;
538 }
539  
540 sub stdout {
541 2 ▶ my($self, $msg) = @_;
Subroutine stdout: called CC=2 SCAR=6.9
Pod undocumented
542 2 ▶ print STDOUT "$msg\n" if $HAS_TERM;
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Setup::HAS_TERM 1 1 2
543 }
544 sub log {
545 1202 ▶ my($self, $msg) = @_;
Subroutine log: called CC=2 SCAR=6.9
Pod undocumented
546 1202 ▶ print STDERR "$msg\n" if $HAS_TERM;
Branch: 1 branch
BranchTrueFalseTotal
if $Module::Setup::HAS_TERM 1 1201 1202
547 }
548 sub dialog {
549 84 ▶ my($self, $msg, $default, $validator_callback) = @_;
Subroutine dialog: called CC=5 SCAR=16.1
Pod undocumented
550 84 ▶ return $default unless $HAS_TERM;
Branch: 1 branch
BranchTrueFalseTotal
unless $Module::Setup::HAS_TERM 80 4 84
551 4 while (1) {
552 9 my $ret = prompt($msg, $default);
553 9 ▶ return $ret unless $validator_callback && ref($validator_callback) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless $validator_callback and ref $validator_callback eq "CODE" 2 7 9
Condition100%3/3
$validator_callback and ref $validator_callback eq "CODE"
!ll&&!rl&&r
117
MC/DC100%2/2
$validator_callback and ref $validator_callback eq "CODE"
$validator_callback ref $validator_callback eq "CODE"
Truth table100%3/3
A and B
A= $validator_callbackB= ref $validator_callback eq "CODE"
ABresult
0X0
100
111
554 7 ▶ return $ret if $validator_callback->($self, $ret);
Branch: 1 branch
BranchTrueFalseTotal
if &$validator_callback($self, $ret) 2 5 7
555 }
556 }
557  
558 sub system {
559 2 ▶ my($self, @args) = @_;
Subroutine system: called CC=1 SCAR=0.0
Pod undocumented
560 2 CORE::system(@args);
561 }
562  
563 40 1;
564 __END__
« blib/lib/Module/Setup/Flavor/SelectVC.pm ↑ Summary blib/lib/Module/Setup/Flavor.pm »