blib/lib/Module/Setup.pm

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