line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Sub::Property::result_postfilter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3999
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
897
|
use Perinci::Sub::PropertyUtil qw(declare_property); |
|
1
|
|
|
|
|
952
|
|
|
1
|
|
|
|
|
773
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.08'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub filter_using_for { |
12
|
2
|
|
|
2
|
0
|
11
|
my ($self, %args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
33
|
|
|
12
|
my $v = $args{new} // $args{value}; |
15
|
2
|
50
|
33
|
|
|
22
|
return unless $v && keys(%$v); |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
8
|
$self->select_section('after_call_after_res_validation'); |
18
|
2
|
|
|
|
|
25
|
$self->push_lines('', '# postfilter result'); |
19
|
|
|
|
|
|
|
|
20
|
2
|
50
|
|
|
|
58
|
my $term = $self->{_meta}{result_naked} ? '$_w_res' : '$_w_res->[2]'; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
3
|
my $errp = "result_postfilter: Unknown filter"; |
23
|
|
|
|
|
|
|
my $gen_process_item = sub { |
24
|
6
|
|
|
6
|
|
10
|
my $t = shift; |
25
|
6
|
|
|
|
|
8
|
my $code = ''; |
26
|
6
|
|
|
|
|
20
|
while (my ($a, $b) = each %$v) { |
27
|
18
|
100
|
|
|
|
48
|
if ($a eq 're') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
28
|
6
|
100
|
|
|
|
20
|
$code .= ($code ? "elsif":"if"). |
29
|
|
|
|
|
|
|
"(ref($t) eq 'Regexp'){"; |
30
|
6
|
50
|
|
|
|
11
|
if ($b eq 'str') { |
31
|
6
|
|
|
|
|
13
|
$code .= "$t = \"$t\""; |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
0
|
die "$errp for $a: $b"; |
34
|
|
|
|
|
|
|
} |
35
|
6
|
|
|
|
|
20
|
$code.="}"; |
36
|
|
|
|
|
|
|
} elsif ($a eq 'date') { |
37
|
6
|
50
|
|
|
|
18
|
$code .= ($code ? "elsif":"if"). |
38
|
|
|
|
|
|
|
"(ref($t) eq 'DateTime'){"; |
39
|
6
|
50
|
|
|
|
11
|
if ($b eq 'epoch') { |
40
|
6
|
|
|
|
|
12
|
$code .= "$t = $t->epoch"; |
41
|
|
|
|
|
|
|
} else { |
42
|
0
|
|
|
|
|
0
|
die "$errp for $a: $b"; |
43
|
|
|
|
|
|
|
} |
44
|
6
|
|
|
|
|
21
|
$code.="}"; |
45
|
|
|
|
|
|
|
} elsif ($a eq 'code') { |
46
|
6
|
100
|
|
|
|
20
|
$code .= ($code ? "elsif":"if"). |
47
|
|
|
|
|
|
|
"(ref($t) eq 'CODE'){"; |
48
|
6
|
50
|
|
|
|
13
|
if ($b eq 'str') { |
49
|
6
|
|
|
|
|
12
|
$code .= "$t = 'CODE'"; |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
0
|
die "$errp for $a: $b"; |
52
|
|
|
|
|
|
|
} |
53
|
6
|
|
|
|
|
18
|
$code.="}"; |
54
|
|
|
|
|
|
|
} else { |
55
|
0
|
|
|
|
|
0
|
die "$errp $a"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
6
|
|
|
|
|
13
|
$code .= "elsif(ref($t) eq 'ARRAY') { \$_w_resf_ary->($t) }"; |
59
|
6
|
|
|
|
|
14
|
$code .= "elsif(ref($t) eq 'HASH') { \$_w_resf_hash->($t) }"; |
60
|
6
|
|
|
|
|
30
|
$code; |
61
|
2
|
|
|
|
|
15
|
}; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
6
|
$self->push_lines( |
64
|
|
|
|
|
|
|
'state $_w_resf_ary; state $_w_resf_hash;'); |
65
|
2
|
|
|
|
|
28
|
$self->push_lines( |
66
|
|
|
|
|
|
|
'if (!$_w_resf_ary ) { $_w_resf_ary = sub { '. |
67
|
|
|
|
|
|
|
'for my $el (@{$_[0]}) { '. |
68
|
|
|
|
|
|
|
$gen_process_item->('$el') . ' } } }' |
69
|
|
|
|
|
|
|
); |
70
|
2
|
|
|
|
|
32
|
$self->push_lines( |
71
|
|
|
|
|
|
|
'if (!$_w_resf_hash) { $_w_resf_hash = sub { '. |
72
|
|
|
|
|
|
|
'my $h=shift; for my $k (keys %$h) { '. |
73
|
|
|
|
|
|
|
$gen_process_item->('$h->{$k}') . ' } } }' |
74
|
|
|
|
|
|
|
); |
75
|
2
|
|
|
|
|
35
|
$self->push_lines( |
76
|
|
|
|
|
|
|
"for ($term) { " . $gen_process_item->('$_') . " }", |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
our $_implementation = 'for'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
declare_property( |
83
|
|
|
|
|
|
|
name => 'result_postfilter', |
84
|
|
|
|
|
|
|
type => 'function', |
85
|
|
|
|
|
|
|
schema => ['hash'], |
86
|
|
|
|
|
|
|
wrapper => { |
87
|
|
|
|
|
|
|
meta => { |
88
|
|
|
|
|
|
|
v => 2, |
89
|
|
|
|
|
|
|
# very low, we want to be the last to process result before |
90
|
|
|
|
|
|
|
# returning it |
91
|
|
|
|
|
|
|
prio => 100, |
92
|
|
|
|
|
|
|
convert => 1, |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
handler => sub { |
95
|
2
|
50
|
|
2
|
|
93338
|
if ($_implementation eq 'for') { |
96
|
2
|
|
|
|
|
9
|
filter_using_for(@_); |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
|
die "Unknown implementation '$_implementation'"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
}, |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
# ABSTRACT: (DEPRECATED) Postfilter function result |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |