line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CatalystX::Eta::Controller::Search; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1384
|
use Moose::Role; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
4
|
2
|
|
|
2
|
|
9941
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
23
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
requires 'list_GET'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
around list_GET => \&Search_arround_list_GET; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub Search_arround_list_GET { |
11
|
3
|
|
|
3
|
|
34372
|
my $orig = shift; |
12
|
3
|
|
|
|
|
7
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
6
|
my ($c) = @_; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
7
|
my %may_search; |
17
|
|
|
|
|
|
|
|
18
|
3
|
50
|
|
|
|
14
|
if ( exists $self->config->{search_ok} ) { |
19
|
3
|
|
|
|
|
191
|
foreach my $key_ok ( keys %{ $self->config->{search_ok} } ) { |
|
3
|
|
|
|
|
10
|
|
20
|
0
|
0
|
|
|
|
0
|
if ( exists $c->req->params->{$key_ok} ) { |
|
|
0
|
|
|
|
|
|
21
|
0
|
|
|
|
|
0
|
$may_search{$key_ok} = $c->req->params->{$key_ok}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
elsif ( exists $c->req->params->{"$key_ok:IN"} ) { |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
push @{ $may_search{$key_ok}{'-or'} }, [ split /\n/, $c->req->params->{"$key_ok:IN"} ]; |
|
0
|
|
|
|
|
0
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
0
|
|
|
|
|
0
|
my $type = $self->config->{search_ok}{$key_ok}; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
0
|
for my $exp ( qw|< > >= <= +< +> +>= +<=|, ( $type eq 'Str' ? qw/like ilike/ : () ) ) { |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
0
|
if ( exists $c->req->params->{"$key_ok:$exp"} ) { |
35
|
0
|
|
|
|
|
0
|
my $tmp = "$exp"; # not more read only |
36
|
0
|
|
|
|
|
0
|
$tmp =~ s/^(\+)?//; |
37
|
0
|
0
|
0
|
|
|
0
|
my $gp = $1 && $1 eq '+' ? '-and' : '-or'; |
38
|
0
|
|
|
|
|
0
|
push @{ $may_search{$key_ok}{$gp} }, { $tmp => $c->req->params->{"$key_ok:$exp"} }; |
|
0
|
|
|
|
|
0
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
176
|
foreach my $key ( keys %may_search ) { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
my $type = $self->config->{search_ok}{$key}; |
48
|
0
|
|
|
|
|
0
|
my $val = $may_search{$key}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
0
|
|
|
0
|
$may_search{$key} = undef, next |
|
|
|
0
|
|
|
|
|
51
|
|
|
|
|
|
|
if ( ( $type eq 'Bool' || $type eq 'Int' || $type eq 'Num' || ref $type eq 'MooseX::Types::TypeDecorator' ) |
52
|
|
|
|
|
|
|
&& $val eq '' ); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $cons = Moose::Util::TypeConstraints::find_or_parse_type_constraint($type); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
0
|
$self->status_bad_request( $c, message => "Unknown type constraint '$type'" ), $c->detach |
57
|
|
|
|
|
|
|
unless defined($cons); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
0
|
if ( ref $val eq 'HASH' ) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# many groups |
62
|
0
|
|
|
|
|
0
|
foreach my $gp ( keys %$val ) { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
foreach my $a_val ( @{ $val->{$gp} } ) { |
|
0
|
|
|
|
|
0
|
|
65
|
0
|
0
|
|
|
|
0
|
my $checkval = ref $a_val eq 'HASH' ? $a_val->{ ( keys %$a_val )[0] } : $a_val; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
0
|
if ( !$cons->check($checkval) ) { |
68
|
0
|
|
|
|
|
0
|
$self->status_bad_request( $c, message => "invalid param $key for $checkval" ); |
69
|
0
|
|
|
|
|
0
|
$c->detach; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# such valided |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
0
|
my $checkval = $val; |
79
|
0
|
0
|
|
|
|
0
|
if ( !$cons->check($checkval) ) { |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
$self->status_bad_request( $c, message => "invalid param $key" ), $c->detach; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
50
|
|
|
10
|
my $base = $self->config->{search_base} || 'me'; |
87
|
3
|
|
|
|
|
178
|
foreach my $k ( keys %may_search ) { |
88
|
0
|
0
|
|
|
|
0
|
my $on_table = $k !~ /\./ ? "$base.$k" : "$k"; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
my $such_val = delete $may_search{$k}; |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
0
|
if ( ref $such_val eq 'HASH' ) { |
93
|
0
|
|
|
|
|
0
|
for my $op ( keys %$such_val ) { |
94
|
0
|
|
|
|
|
0
|
push @{ $may_search{$op} }, map { +{ $on_table => $_ } } @{ $such_val->{$op} }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
0
|
$may_search{$on_table} = $such_val; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
3
|
50
|
|
|
|
12
|
$c->stash->{collection} = $c->stash->{collection}->search( {%may_search} ) |
104
|
|
|
|
|
|
|
if %may_search; |
105
|
|
|
|
|
|
|
|
106
|
3
|
50
|
33
|
|
|
11
|
if ( exists $c->req->params->{limit_rows} && $c->req->params->{limit_rows} =~ /^[0-9]+$/ ) { |
107
|
|
|
|
|
|
|
$c->stash->{collection} = $c->stash->{collection}->search( |
108
|
|
|
|
|
|
|
undef, |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
rows => $c->req->params->{limit_rows} |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
0
|
); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
3
|
|
|
|
|
280
|
$self->$orig(@_); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|