line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::Query::Clause; |
2
|
8
|
|
|
8
|
|
45
|
use Moo; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
60
|
|
3
|
8
|
|
|
8
|
|
2489
|
use Carp; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
709
|
|
4
|
8
|
|
|
8
|
|
49
|
use Scalar::Util qw( blessed ); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
801
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
4
|
|
|
4
|
|
12
|
'""' => sub { $_[0]->stringify; }, |
7
|
577
|
|
|
577
|
|
3454
|
'bool' => sub {1}, |
8
|
8
|
|
|
8
|
|
46
|
fallback => 1; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
96
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
703
|
use namespace::autoclean; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
96
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.306'; |
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
|
662
|
my $self = shift; |
59
|
487
|
|
|
|
|
2357
|
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
|
76
|
my $self = shift; |
72
|
50
|
50
|
|
|
|
105
|
return undef unless $self->is_tree; |
73
|
50
|
|
|
|
|
86
|
my $clauses = 0; |
74
|
|
|
|
|
|
|
$self->{value}->walk( |
75
|
|
|
|
|
|
|
sub { |
76
|
92
|
|
|
92
|
|
174
|
my ( $clause, $dialect, $code, $prefix ) = @_; |
77
|
92
|
|
|
|
|
112
|
$clauses++; |
78
|
92
|
50
|
|
|
|
223
|
if ( $clause->is_tree ) { |
79
|
0
|
|
|
|
|
0
|
$clause->{value}->walk($code); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
50
|
|
|
|
|
317
|
); |
83
|
50
|
|
|
|
|
381
|
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
|
7
|
my $self = shift; |
98
|
4
|
100
|
|
|
|
8
|
if ( $self->is_tree ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
99
|
1
|
|
|
|
|
7
|
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
|
|
|
33
|
return sprintf( "%s%s%s", |
|
|
|
50
|
|
|
|
|
123
|
|
|
|
|
|
|
( $self->field || '' ), |
124
|
|
|
|
|
|
|
( $self->op || '' ), |
125
|
|
|
|
|
|
|
$self->value, ); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |