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