lib/PEF/Front/Model.pm

filter: Statementstmt 59.6% 31 / 52 Branchbran 50.0% 12 / 24 Conditioncond 23.5% 4 / 17 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 3 totaltotal 47.7% 54 / 113 CC 20 SCAR 38.3
CC
20
Cov
51%
make_model_call
110.0
_chain_links_sub
9.3
normalize_method_name
3.0
CRAP 46.1
« blib/lib/PEF/Front/Route.pm ↑ Summary blib/lib/PEF/Front/Response.pm »
1 package PEF::Front::Model;
2  
3 1 ▶use PEF::Front::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶sub normalize_method_name {
Subroutine normalize_method_name: called CC=3 SCAR=11.0
Pod undocumented
9 9 my $name = $_[0];
10 9 ▶ if ($name =~ /^\^?PEF::Front/ || $name =~ /^\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\^?PEF::Front/ or $name =~ /^\^/) { } 5 4 9
Condition66%2/3
$name =~ /^\^?PEF::Front/ or $name =~ /^\^/
l!l&&r!l&&!r
054
MC/DC50%1/2
$name =~ /^\^?PEF::Front/ or $name =~ /^\^/
$name =~ /^\^?PEF::Front/ $name =~ /^\^/
Truth table66%2/3
A or B
A= $name =~ /^\^?PEF::Front/B= $name =~ /^\^/
ABresult
1X1
011
000
11 5 $name =~ s/^\^//;
12 } else {
13 4 $name = cfg_app_namespace . "Local::$name";
14 }
15 9 $name;
16 }
17  
18 0 ▶sub make_model_call {
Subroutine make_model_call: not called CC=10 SCAR=47.0
Pod undocumented
19 0 my ($method, $model) = @_;
20 0 my ($model_sub, $cfg_model_sub);
21 0 ▶ if ($model && !ref($model) && $model =~ /^\^?\w+::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($model and not ref $model and $model =~ /^\^?\w+::/) { } 0 0 0
Condition0%0/6
$model and not ref $model and $model =~ /^\^?\w+::/
!ll&&!rl&&r
000
$model and not ref $model
!ll&&!rl&&r
000
MC/DC0%0/3
$model and not ref $model and $model =~ /^\^?\w+::/
$model not ref $model $model =~ /^\^?\w+::/
Truth table0%0/4
A and not(B) and C
A= $modelB= not ref $modelC= $model =~ /^\^?\w+::/
ABCresult
0XX0
10X0
1100
1111
22 0 $model = normalize_method_name($model);
23 0 my $class = substr($model, 0, rindex($model, "::"));
24 0 my $can = substr($model, rindex($model, "::") + 2);
25 0 eval "use $class";
26 0 ▶ $@ = "$class must contain $can function" if not $@ and not $class->can($can);
Branch: 1 branch
BranchTrueFalseTotal
unless $@ or $class->can($can) 0 0 0
Condition0%0/3
$@ or $class->can($can)
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or $class->can($can)
$@ $class->can($can)
Truth table0%0/3
A or B
A= $@B= $class->can($can)
ABresult
1X1
011
000
27 0 ▶ die {
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
28 result => 'INTERR',
29 answer => 'Validator $1 loading model error: $2',
30 answer_args => [$method, "$@"],
31 }
32 if $@;
33 0 $model_sub = eval "sub { eval { $model(\@_) } }";
34 } else {
35 0 ▶ $model ||= 'rpc_site';
Condition0%0/2
$model ||= "rpc_site"
l!l
00
MC/DC0%0/1
$model ||= "rpc_site"
$model
Truth table0%0/2
A
A= $model
Aresult
11
00
36 0 $cfg_model_sub = eval {cfg_model_rpc($model)};
37 0 ▶ $@ = "cfg_model_rpc('$model') must return code reference" if ref $cfg_model_sub ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cfg_model_sub ne "CODE" 0 0 0
38 0 ▶ die {
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
39 result => 'INTERR',
40 answer => 'Validator $1 loading model error: $2',
41 answer_args => [$method, "$@"],
42 }
43 if $@;
44 0 $model_sub = eval "sub { eval { \$cfg_model_sub->(\@_) } }";
45 }
46 0 return ($model, $model_sub);
47 }
48  
49 5 ▶sub _chain_links_sub {
Subroutine _chain_links_sub: called CC=9 SCAR=22.3
50 5 my $links = $_[0];
51 5 ▶ $links = [$links] if not ref $links or ref $links ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $links or ref $links ne "ARRAY" 1 4 5
Condition66%2/3
not ref $links or ref $links ne "ARRAY"
l!l&&r!l&&!r
104
MC/DC50%1/2
not ref $links or ref $links ne "ARRAY"
not ref $links ref $links ne "ARRAY"
Truth table66%2/3
not(A) or B
A= not ref $linksB= ref $links ne "ARRAY"
ABresult
1X1
011
000
52 5 my @handlers;
53 5 for my $link (@$links) {
54 9 ▶ if (not ref $link) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $link) { } 6 3 9
elsif (ref $link eq 'HASH') { } 3 0 3
55 6 push @handlers, normalize_method_name($link);
56 } elsif (ref $link eq 'HASH') {
57 3 push @handlers, map {[normalize_method_name($_), $link->{$_}]} keys %$link;
58 }
59 }
60 5 my $sub_str = <<EOS;
61 sub {
62 my (\$req, \$context) = \@_;
63 my \$response;
64 EOS
65 5 ▶ for (my $i = 0; $i < @handlers; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @handlers) 9 5 14
66 9 ▶ if (ref $handlers[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handlers[$i]) { } 3 6 9
67 3 $sub_str .= "\t\$response = $handlers[$i][0](\$req, \$context, \$response, \$handlers[$i][1]);\n";
68 } else {
69 6 $sub_str .= "\t\$response = $handlers[$i](\$req, \$context, \$response);\n";
70 }
71 }
72 5 $sub_str .= "\t\$response;\n}\n";
73 5 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 5 5
74 0 my $sub = eval $sub_str;
75 0 return ($sub, $sub_str);
76 } else {
77 5 return $sub_str;
78 }
79 }
80  
81 0 ▶sub chain_links {
Subroutine chain_links: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my ($sub, $sub_str) = _chain_links_sub($_[0]);
83 0 return $sub;
84 }
85  
86 1 1;
87  
88 __END__
« blib/lib/PEF/Front/Route.pm ↑ Summary blib/lib/PEF/Front/Response.pm »