line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::Query::Clause; |
2
|
9
|
|
|
9
|
|
54
|
use Moo; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
60
|
|
3
|
9
|
|
|
9
|
|
2444
|
use Carp; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
668
|
|
4
|
9
|
|
|
9
|
|
51
|
use Scalar::Util qw( blessed ); |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
890
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
4
|
|
|
4
|
|
9
|
'""' => sub { $_[0]->stringify; }, |
7
|
587
|
|
|
587
|
|
2692
|
'bool' => sub {1}, |
8
|
9
|
|
|
9
|
|
44
|
fallback => 1; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
104
|
|
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
880
|
use namespace::autoclean; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
76
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.307'; |
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
|
493
|
|
|
493
|
1
|
440
|
my $self = shift; |
59
|
493
|
|
|
|
|
1705
|
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
|
51
|
my $self = shift; |
72
|
50
|
50
|
|
|
|
72
|
return undef unless $self->is_tree; |
73
|
50
|
|
|
|
|
61
|
my $clauses = 0; |
74
|
|
|
|
|
|
|
$self->{value}->walk( |
75
|
|
|
|
|
|
|
sub { |
76
|
92
|
|
|
92
|
|
120
|
my ( $clause, $dialect, $code, $prefix ) = @_; |
77
|
92
|
|
|
|
|
79
|
$clauses++; |
78
|
92
|
50
|
|
|
|
118
|
if ( $clause->is_tree ) { |
79
|
0
|
|
|
|
|
0
|
$clause->{value}->walk($code); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
50
|
|
|
|
|
257
|
); |
83
|
50
|
|
|
|
|
292
|
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
|
5
|
my $self = shift; |
98
|
4
|
100
|
|
|
|
6
|
if ( $self->is_tree ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
99
|
1
|
|
|
|
|
6
|
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
|
|
|
28
|
return sprintf( "%s%s%s", |
|
|
|
50
|
|
|
|
|
123
|
|
|
|
|
|
|
( $self->field || '' ), |
124
|
|
|
|
|
|
|
( $self->op || '' ), |
125
|
|
|
|
|
|
|
$self->value, ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |