ComponentsFromConfig/Role/PluginRole.pm

filter: Statementstmt 100% 49 / 49 Branchbran 50.0% 2 / 4 Conditioncond 55.5% 10 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 80.0% 72 / 90 CC 13 SCAR 16.9
CC
13
Cov
86%
__ANON__
7.7
_setup_dynamic_model
7.7
__ANON__
1.0
CRAP 5.4
↑ Summary ComponentsFromConfig/Role/AdaptorRole.pm »
1 package CatalystX::ComponentsFromConfig::Role::PluginRole;
2 1 $CatalystX::ComponentsFromConfig::Role::PluginRole::VERSION = '1.006';
3 {
4 1 $CatalystX::ComponentsFromConfig::Role::PluginRole::DIST = 'CatalystX-ComponentsFromConfig';
5 }
6 2 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MooseX::Types::Moose qw/Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::Types::Common::String qw/LowerCaseSimpleStr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use CatalystX::InjectComponent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: parameterised role for plugins to create components from configuration
13  
14  
15 1 parameter component_type => (
16 isa => LowerCaseSimpleStr,
17 required => 1,
18 );
19  
20  
21 1 parameter skip_mvc_renaming => (
22 isa => Bool,
23 default => 0,
24 );
25  
26  
27 4 ▶role {
Subroutine __ANON__: called CC=1 SCAR=0.1
28 4 my $params = shift;
29 4 my $type = $params->component_type;
30 4 my $uctype = ucfirst($params->component_type);
31  
32 4 ▶ after 'setup_components' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 4 my $method = "_setup_dynamic_$type";
34 4 shift->$method(@_);
35 4 };
36  
37 2 ▶ method "_setup_dynamic_$type" => sub {
Subroutine __ANON__: called CC=7 SCAR=20.4
Subroutine _setup_dynamic_model: called CC=7 SCAR=20.4
38 2 my ($app) = @_;
39  
40 2 ▶ my $plugin_config = $app->config->{"${type}s_from_config"} || {};
Condition75%3/4
$app->config->{"${type}s_from_config"} || {}
l!l
02
$app->config->{"${type}s_from_config"} || {}
l!l
11
MC/DC0%0/1
$app->config->{"${type}s_from_config"} || {}
$app->config->{"${type}s_from_config"}
MC/DC100%1/1
$app->config->{"${type}s_from_config"} || {}
$app->config->{"${type}s_from_config"}
Truth table50%1/2
A
A= $app->config->{"${type}s_from_config"}
Aresult
11
00
Truth table100%2/2
A
A= $app->config->{"${type}s_from_config"}
Aresult
11
00
41  
42 2 my $prefix = "${uctype}::";
43  
44 my $base_class = $plugin_config->{base_class} ||
45 2 ▶ "CatalystX::ComponentsFromConfig::${uctype}Adaptor";
Condition75%3/4
$plugin_config->{'base_class'} || "CatalystX::ComponentsFromConfig::${uctype}Adaptor"
l!l
02
$plugin_config->{'base_class'} || "CatalystX::ComponentsFromConfig::${uctype}Adaptor"
l!l
11
MC/DC0%0/1
$plugin_config->{'base_class'} || "CatalystX::ComponentsFromConfig::${uctype}Adaptor"
$plugin_config->{'base_class'}
MC/DC100%1/1
$plugin_config->{'base_class'} || "CatalystX::ComponentsFromConfig::${uctype}Adaptor"
$plugin_config->{'base_class'}
Truth table50%1/2
A
A= $plugin_config->{'base_class'}
Aresult
11
00
Truth table100%2/2
A
A= $plugin_config->{'base_class'}
Aresult
11
00
46  
47 2 ▶ my $config = $app->config || {};
Condition50%2/4
$app->config || {}
l!l
20
$app->config || {}
l!l
20
MC/DC0%0/1
$app->config || {}
$app->config
MC/DC0%0/1
$app->config || {}
$app->config
Truth table50%1/2
A
A= $app->config
Aresult
11
00
Truth table50%1/2
A
A= $app->config
Aresult
11
00
48  
49 2 foreach my $comp_name ( grep { /^\Q$prefix\E/ } keys %$config ) {
50 2 ▶ unless ($app->component($comp_name)) {
Branch: 2 branches
BranchTrueFalseTotal
unless ($app->component($comp_name)) 2 0 2
unless ($app->component($comp_name)) 2 0 2
51 my $local_base_class =
52 2 ▶ $config->{$comp_name}{base_class} || $base_class;
Condition33%2/6
$config->{$comp_name}{'base_class'} || $base_class
l!l&&r!l&&!r
020
$config->{$comp_name}{'base_class'} || $base_class
l!l&&r!l&&!r
020
MC/DC0%0/2
$config->{$comp_name}{'base_class'} || $base_class
$config->{$comp_name}{'base_class'} $base_class
MC/DC0%0/2
$config->{$comp_name}{'base_class'} || $base_class
$config->{$comp_name}{'base_class'} $base_class
Truth table33%1/3
A || B
A= $config->{$comp_name}{'base_class'}B= $base_class
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $config->{$comp_name}{'base_class'}B= $base_class
ABresult
1X1
011
000
53 2 CatalystX::InjectComponent->inject(
54 skip_mvc_renaming => $params->skip_mvc_renaming,
55 into => $app,
56 component => $local_base_class,
57 as => $comp_name,
58 );
59 }
60 }
61 4 };
62 1 };
63  
64 1 1;
65  
66 __END__
↑ Summary ComponentsFromConfig/Role/AdaptorRole.pm »