| 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
Condition66%2/3
$name =~ /^\^?PEF::Front/ or $name =~ /^\^/
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 =~ /^\^/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$model and not ref $model and $model =~ /^\^?\w+::/
$model and not ref $model
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+::/
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$@ or $class->can($can)
MC/DC0%0/2
$@ or $class->can($can)
$@
$class->can($can)
Truth table0%0/3
A or B
A= $@B= $class->can($can)
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | die { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$model ||= "rpc_site"
$model
Truth table0%0/2
A
A= $model
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | die { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
not ref $links or ref $links ne "ARRAY"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | my @handlers; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | for my $link (@$links) { | |||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | ▶ | if (not ref $link) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | if (ref $handlers[$i]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||