line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::Query::Clause; |
2
|
8
|
|
|
8
|
|
42
|
use Moo; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
56
|
|
3
|
8
|
|
|
8
|
|
2462
|
use Carp; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
618
|
|
4
|
8
|
|
|
8
|
|
44
|
use Scalar::Util qw( blessed ); |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
697
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
4
|
|
|
4
|
|
19
|
'""' => sub { $_[0]->stringify; }, |
7
|
577
|
|
|
577
|
|
3415
|
'bool' => sub {1}, |
8
|
8
|
|
|
8
|
|
45
|
fallback => 1; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
87
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
651
|
use namespace::autoclean; |
|
8
|
|
|
|
|
28
|
|
|
8
|
|
|
|
|
70
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.305'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'field' => ( is => 'rw' ); |
15
|
|
|
|
|
|
|
has 'op' => ( is => 'rw' ); |
16
|
|
|
|
|
|
|
has 'value' => ( is => 'rw' ); |
17
|
|
|
|
|
|
|
has 'quote' => ( is => 'rw' ); |
18
|
|
|
|
|
|
|
has 'proximity' => ( is => 'rw' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Search::Query::Clause - part of a Dialect |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $clause = Search::Query::Clause->new( |
27
|
|
|
|
|
|
|
field => 'color', |
28
|
|
|
|
|
|
|
op => '=', |
29
|
|
|
|
|
|
|
value => 'green', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
my $query = Search::Query->parser->parse("color=red"); |
32
|
|
|
|
|
|
|
$query->add_or_clause( $clause ); |
33
|
|
|
|
|
|
|
print $query; # +color=red color=green |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 DESCRIPTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
A Clause object represents a leaf in a Query Dialect tree. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 field |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 op |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 value |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 quote |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 proximity |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 is_tree |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns true if the Clause has child Clauses. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub is_tree { |
58
|
487
|
|
|
487
|
1
|
476
|
my $self = shift; |
59
|
487
|
|
|
|
|
1959
|
return blessed( $self->{value} ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 has_children |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Returns the number of child Clauses if is_tree() is true. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns undef if is_tree() is false. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub has_children { |
71
|
50
|
|
|
50
|
1
|
59
|
my $self = shift; |
72
|
50
|
50
|
|
|
|
80
|
return undef unless $self->is_tree; |
73
|
50
|
|
|
|
|
63
|
my $clauses = 0; |
74
|
|
|
|
|
|
|
$self->{value}->walk( |
75
|
|
|
|
|
|
|
sub { |
76
|
92
|
|
|
92
|
|
123
|
my ( $clause, $dialect, $code, $prefix ) = @_; |
77
|
92
|
|
|
|
|
70
|
$clauses++; |
78
|
92
|
50
|
|
|
|
137
|
if ( $clause->is_tree ) { |
79
|
0
|
|
|
|
|
0
|
$clause->{value}->walk($code); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
50
|
|
|
|
|
294
|
); |
83
|
50
|
|
|
|
|
313
|
return $clauses; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 stringify |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns Clause as a string. Like Dialect, string-like operators |
89
|
|
|
|
|
|
|
are overloaded to call stringify(). |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
NOTE that stringify() is not necessarily called by the parent |
92
|
|
|
|
|
|
|
Dialect object when the Dialect object is stringifying itself. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub stringify { |
97
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
98
|
4
|
100
|
|
|
|
11
|
if ( $self->is_tree ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
99
|
1
|
|
|
|
|
12
|
return sprintf( "(%s)", $self->value ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif ( $self->proximity ) { |
102
|
0
|
|
|
|
|
0
|
return sprintf( "%s%s%s%s%s~%d", |
103
|
|
|
|
|
|
|
$self->field, $self->op, $self->quote, |
104
|
|
|
|
|
|
|
$self->value, $self->quote, $self->proximity ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
elsif ( $self->quote ) { |
107
|
0
|
|
|
|
|
0
|
return sprintf( "%s%s%s%s%s", |
108
|
|
|
|
|
|
|
$self->field, $self->op, $self->quote, |
109
|
|
|
|
|
|
|
$self->value, $self->quote ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
elsif ( ref $self->value ) { |
112
|
0
|
0
|
|
|
|
0
|
if ( $self->op eq '..' ) { |
|
|
0
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
return sprintf( "%s=(%s..%s)", |
114
|
|
|
|
|
|
|
$self->field, $self->value->[0], $self->value->[1] ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
elsif ( $self->op eq '!..' ) { |
117
|
0
|
|
|
|
|
0
|
return sprintf( "%s!=(%s..%s)", |
118
|
|
|
|
|
|
|
$self->field, $self->value->[0], $self->value->[1] ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
3
|
|
50
|
|
|
45
|
return sprintf( "%s%s%s", |
|
|
|
50
|
|
|
|
|
123
|
|
|
|
|
|
|
( $self->field || '' ), |
124
|
|
|
|
|
|
|
( $self->op || '' ), |
125
|
|
|
|
|
|
|
$self->value, ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |