line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PEF::Front::Model; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15420
|
use PEF::Front::Config; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
505
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub normalize_method_name { |
9
|
9
|
|
|
9
|
0
|
15
|
my $name = $_[0]; |
10
|
9
|
100
|
66
|
|
|
46
|
if ($name =~ /^\^?PEF::Front/ || $name =~ /^\^/) { |
11
|
5
|
|
|
|
|
14
|
$name =~ s/^\^//; |
12
|
|
|
|
|
|
|
} else { |
13
|
4
|
|
|
|
|
12
|
$name = cfg_app_namespace . "Local::$name"; |
14
|
|
|
|
|
|
|
} |
15
|
9
|
|
|
|
|
27
|
$name; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub make_model_call { |
19
|
0
|
|
|
0
|
0
|
0
|
my ($method, $model) = @_; |
20
|
0
|
|
|
|
|
0
|
my ($model_sub, $cfg_model_sub); |
21
|
0
|
0
|
0
|
|
|
0
|
if ($model && !ref($model) && $model =~ /^\^?\w+::/) { |
|
|
|
0
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
$model = normalize_method_name($model); |
23
|
0
|
|
|
|
|
0
|
my $class = substr($model, 0, rindex($model, "::")); |
24
|
0
|
|
|
|
|
0
|
my $can = substr($model, rindex($model, "::") + 2); |
25
|
0
|
|
|
|
|
0
|
eval "use $class"; |
26
|
0
|
0
|
0
|
|
|
0
|
$@ = "$class must contain $can function" if not $@ and not $class->can($can); |
27
|
0
|
0
|
|
|
|
0
|
die { |
28
|
|
|
|
|
|
|
result => 'INTERR', |
29
|
|
|
|
|
|
|
answer => 'Validator $1 loading model error: $2', |
30
|
|
|
|
|
|
|
answer_args => [$method, "$@"], |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
if $@; |
33
|
0
|
|
|
|
|
0
|
$model_sub = eval "sub { eval { $model(\@_) } }"; |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
|
0
|
|
|
0
|
$model ||= 'rpc_site'; |
36
|
0
|
|
|
|
|
0
|
$cfg_model_sub = eval {cfg_model_rpc($model)}; |
|
0
|
|
|
|
|
0
|
|
37
|
0
|
0
|
|
|
|
0
|
$@ = "cfg_model_rpc('$model') must return code reference" if ref $cfg_model_sub ne 'CODE'; |
38
|
0
|
0
|
|
|
|
0
|
die { |
39
|
|
|
|
|
|
|
result => 'INTERR', |
40
|
|
|
|
|
|
|
answer => 'Validator $1 loading model error: $2', |
41
|
|
|
|
|
|
|
answer_args => [$method, "$@"], |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
if $@; |
44
|
0
|
|
|
|
|
0
|
$model_sub = eval "sub { eval { \$cfg_model_sub->(\@_) } }"; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
return ($model, $model_sub); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _chain_links_sub { |
50
|
5
|
|
|
5
|
|
2288
|
my $links = $_[0]; |
51
|
5
|
100
|
66
|
|
|
30
|
$links = [$links] if not ref $links or ref $links ne 'ARRAY'; |
52
|
5
|
|
|
|
|
8
|
my @handlers; |
53
|
5
|
|
|
|
|
11
|
for my $link (@$links) { |
54
|
9
|
100
|
|
|
|
24
|
if (not ref $link) { |
|
|
50
|
|
|
|
|
|
55
|
6
|
|
|
|
|
12
|
push @handlers, normalize_method_name($link); |
56
|
|
|
|
|
|
|
} elsif (ref $link eq 'HASH') { |
57
|
3
|
|
|
|
|
9
|
push @handlers, map {[normalize_method_name($_), $link->{$_}]} keys %$link; |
|
3
|
|
|
|
|
6
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
5
|
|
|
|
|
9
|
my $sub_str = <
|
61
|
|
|
|
|
|
|
sub { |
62
|
|
|
|
|
|
|
my (\$req, \$context) = \@_; |
63
|
|
|
|
|
|
|
my \$response; |
64
|
|
|
|
|
|
|
EOS |
65
|
5
|
|
|
|
|
14
|
for (my $i = 0; $i < @handlers; ++$i) { |
66
|
9
|
100
|
|
|
|
17
|
if (ref $handlers[$i]) { |
67
|
3
|
|
|
|
|
12
|
$sub_str .= "\t\$response = $handlers[$i][0](\$req, \$context, \$response, \$handlers[$i][1]);\n"; |
68
|
|
|
|
|
|
|
} else { |
69
|
6
|
|
|
|
|
23
|
$sub_str .= "\t\$response = $handlers[$i](\$req, \$context, \$response);\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
5
|
|
|
|
|
8
|
$sub_str .= "\t\$response;\n}\n"; |
73
|
5
|
50
|
|
|
|
12
|
if (wantarray) { |
74
|
0
|
|
|
|
|
0
|
my $sub = eval $sub_str; |
75
|
0
|
|
|
|
|
0
|
return ($sub, $sub_str); |
76
|
|
|
|
|
|
|
} else { |
77
|
5
|
|
|
|
|
17
|
return $sub_str; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub chain_links { |
82
|
0
|
|
|
0
|
0
|
|
my ($sub, $sub_str) = _chain_links_sub($_[0]); |
83
|
0
|
|
|
|
|
|
return $sub; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |