blib/lib/Module/Setup/Flavor.pm

filter: Statementstmt 100% 80 / 80 Branchbran 96.6% 29 / 30 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 12 / 12 Podpod 50.0% 3 / 6 totaltotal 97.1% 134 / 138 CC 24 SCAR 19.8
CC
24
Cov
99%
_import_template
12.0
import_template
8.0
loader
6.0
CRAP 7.2
« blib/lib/Module/Setup/Flavor/SelectVC.pm ↑ Summary blib/lib/Module/Setup.pm »
1 package Module::Setup::Flavor;
2 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 32 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 32 ▶use Storable ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 32 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 57 ▶sub new { bless {}, shift }
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10  
11 32 my %data_cache;
12 73 ▶sub loader {
Subroutine loader: called CC=6 SCAR=17.9
Pod undocumented
13 73 my $self = shift;
14 73 my $class = ref($self);
15 73 ▶ $class = $self unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 18 55 73
16  
17 73 ▶ unless ($data_cache{$class}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data_cache{$class}) 47 26 73
18 47 local $/;
19 47 my $data = eval "package $class; <DATA>"; ## no critic
20 47 ▶ Carp::croak "flavor template class is invalid: $class" unless $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 1 46 47
21  
22 46 my @template = YAML::Load(join '', $data);
23 46 ▶ if (scalar(@template) == 1 && !defined $template[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @template == 1 and not defined $template[0]) { } 1 45 46
Condition100%3/3
scalar @template == 1 and not defined $template[0]
!ll&&!rl&&r
31141
MC/DC100%2/2
scalar @template == 1 and not defined $template[0]
scalar @template == 1 not defined $template[0]
Truth table100%3/3
A and not(B)
A= scalar @template == 1B= not defined $template[0]
ABresult
0X0
100
111
24 1 $data_cache{$class} = [];
25 } else {
26 45 $data_cache{$class} = \@template;
27 }
28 };
29 72 @{ Storable::dclone($data_cache{$class}) };
30 }
31  
32 9 ▶sub _import_template {
Subroutine _import_template: called CC=12 SCAR=24.9
33 9 my($self, $base_class, $args) = @_;
34  
35 9 eval "require $base_class"; ## no critic
36 9 ▶ Carp::croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 8 9
37  
38 8 my @base_template = $base_class->loader;
39 8 my @template;
40 LOOP:
41 8 for my $tmpl (@base_template) {
42 68 ▶ if (exists $tmpl->{config}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpl->{"config"}) 7 61 68
43 7 ▶ $args->{template_config} = $tmpl unless $args->{template_config};
Branch: 1 branch
BranchTrueFalseTotal
unless $args->{"template_config"} 5 2 7
44 7 next;
45 }
46 61 for my $type (qw/ file plugin dir /) {
47 77 ▶ next unless exists $tmpl->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tmpl->{$type} 18 59 77
48 59 my $key = "$type - $tmpl->{$type}";
49 59 ▶ next LOOP if $args->{template_loaded}->{$key}++;
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"template_loaded"}{$key}++ 1 58 59
50 58 my $template = delete $args->{template_index}->{$key};
51  
52 58 ▶ if (ref($template) eq 'HASH' && $template->{patch}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $template eq "HASH" and $template->{"patch"}) 3 55 58
Condition100%3/3
ref $template eq "HASH" and $template->{"patch"}
!ll&&!rl&&r
5143
MC/DC100%2/2
ref $template eq "HASH" and $template->{"patch"}
ref $template eq "HASH" $template->{"patch"}
Truth table100%3/3
A and B
A= ref $template eq "HASH"B= $template->{"patch"}
ABresult
0X0
100
111
53 # apply patch
54 3 eval "require Text::Patch;";
55 3 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
56 3 $template->{template} = Text::Patch::patch( $tmpl->{template}, $template->{patch}, STYLE => 'Unified' );
57 }
58  
59 58 ▶ $template = $tmpl unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 51 7 58
60 58 push @template, $template;
61 58 next LOOP;
62 }
63 2 push @template, $tmpl;
64 }
65  
66 8 @template;
67 }
68  
69 8 ▶sub import_template {
Subroutine import_template: called CC=8 SCAR=20.8
Pod undocumented
70 8 my($self, @base_classes) = @_;
71 8 my $class = ref($self);
72  
73 8 my @local_template = loader($self);
74  
75 8 my %template_index;
76 my $template_config;
77 8 my $anthor_key_count = 0;
78 LOOP:
79 8 for my $tmpl (@local_template) {
80 15 ▶ if (exists $tmpl->{config}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tmpl->{"config"}) 2 13 15
81 2 $template_config = $tmpl;
82 2 next;
83 }
84 13 for my $type (qw/ file plugin dir /) {
85 23 ▶ next unless exists $tmpl->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $tmpl->{$type} 12 11 23
86 11 $template_index{"$type - $tmpl->{$type}"} = $tmpl;
87 11 next LOOP;
88 }
89 2 $template_index{'anthor - ' . $anthor_key_count++} = $tmpl;
90 }
91  
92 8 my $args = {
93 template_config => $template_config,
94 template_index => \%template_index,
95 };
96 8 my @template;
97 8 for my $base_class (reverse @base_classes) {
98 9 push @template, $self->_import_template($base_class, $args);
99 }
100  
101 7 for my $tmpl (values %{ $args->{template_index} }) {
102 2 push @template, $tmpl;
103 }
104 7 ▶ push @template, $args->{template_config} if $args->{template_config};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"template_config"} 6 1 7
105  
106 7 @template;
107 }
108  
109 50 ▶sub setup_flavor { 1 }
Subroutine setup_flavor: called CC=1 SCAR=0.0
Pod documented
110  
111 13 ▶sub setup_config {
Subroutine setup_config: called CC=1 SCAR=0.0
Pod documented
112 13 my($self, $context, $config) = @_;
113 }
114  
115 5 ▶sub setup_additional {
Subroutine setup_additional: called CC=1 SCAR=0.0
Pod documented
116 5 my($self, $context, $config) = @_;
117 }
118  
119  
120 32 1;
121  
122 =head1 NAME
123  
124 Module::Setup::Flavor - Module::Setup Flavor
125  
126 =head1 Flavor Hook Point
127  
128 =head2 setup_flavor
129  
130 flavor setup, if return value is false is exit create flavor
131  
132 =head2 setup_config
133  
134 before flavors plugin load
135  
136 =head2 setup_additional
137  
138 end of additional flavor install
139  
140 =cut
141  
142 __DATA__
« blib/lib/Module/Setup/Flavor/SelectVC.pm ↑ Summary blib/lib/Module/Setup.pm »