DynamicComponent/ModelsFromConfig.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 100% 8 / 8 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 92.9% 53 / 57 CC 8 SCAR 15.6
CC
8
Cov
94%
_setup_dynamic_models
8.0
COMPONENT
1.0
__ANON__
1.0
CRAP 4.7
« DynamicComponent/ModelsFromConfig/InterfaceRoles.pm ↑ Summary DynamicComponent/ModelToControllerReflector/Strategy.pm »
1 package CatalystX::DynamicComponent::ModelsFromConfig;
2 6 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Catalyst::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 requires qw/
7 config
8 setup_components
9 setup_component
10 /;
11  
12 # Note method reaming - allows user to modify my setup_dynamic_component without being
13 # forced to do it globally.
14 with 'CatalystX::DynamicComponent' => {
15 name => '_setup_dynamic_model',
16 methods => {
17 2 ▶ COMPONENT => sub {
Subroutine __ANON__: called CC=1 SCAR=0.2
Subroutine COMPONENT: called CC=1 SCAR=0.2
18 2 my ($component_class_name, $app, $args) = @_;
19  
20 2 my $class = $args->{class};
21 2 Class::MOP::load_class($class);
22
23 0 $class->new($args);
24 },
25 },
26 6 };
27  
28 6 ▶after 'setup_components' => sub { shift->_setup_dynamic_models(@_); };
Subroutine __ANON__: called CC=1 SCAR=0.0
29  
30 6 ▶sub _setup_dynamic_models {
Subroutine _setup_dynamic_models: called CC=8 SCAR=20.8
31 6 my ($app) = @_;
32  
33 6 my $model_prefix = 'Model::';
34  
35 6 ▶ my $config = $app->config || {};
Condition50%1/2
$app->config || {}
l!l
60
MC/DC0%0/1
$app->config || {}
$app->config
Truth table50%1/2
A
A= $app->config
Aresult
11
00
36 6 ▶ my $myconfig = $config->{'CatalystX::DynamicComponent::ModelsFromConfig'} || {};
Condition100%2/2
$config->{'CatalystX::DynamicComponent::ModelsFromConfig'} || {}
l!l
42
MC/DC100%1/1
$config->{'CatalystX::DynamicComponent::ModelsFromConfig'} || {}
$config->{'CatalystX::DynamicComponent::ModelsFromConfig'}
Truth table100%2/2
A
A= $config->{'CatalystX::DynamicComponent::ModelsFromConfig'}
Aresult
11
00
37  
38 6 foreach my $model_name ( grep { /^$model_prefix/ } keys %$config ) {
39 8 ▶ if (my $inc = $myconfig->{include}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $inc = $myconfig->{"include"}) 6 2 8
40 6 ▶ next unless $model_name =~ /$inc/;
Branch: 1 branch
BranchTrueFalseTotal
unless $model_name =~ /$inc/ 1 5 6
41 }
42 7 ▶ if (my $exc = $myconfig->{exclude}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exc = $myconfig->{"exclude"}) 4 3 7
43 4 ▶ next if $model_name =~ /$exc/;
Branch: 1 branch
BranchTrueFalseTotal
if $model_name =~ /$exc/ 1 3 4
44 }
45 $app->_setup_dynamic_model( $model_name,
46 $app->_setup_dynamic_model_config( $model_name,
47 6 Catalyst::Utils::merge_hashes($myconfig, $config->{$model_name}) )
48 );
49 }
50 }
51  
52 5 ▶sub _setup_dynamic_model_config {
Subroutine _setup_dynamic_model_config: called CC=1 SCAR=0.0
53 5 my ($app, $model_name, $config) = @_;
54 5 return $config;
55 }
56  
57 6 1;
58  
59 __END__
« DynamicComponent/ModelsFromConfig/InterfaceRoles.pm ↑ Summary DynamicComponent/ModelToControllerReflector/Strategy.pm »