File Coverage

blib/lib/Text/Query/Build.pm
Criterion Covered Total %
statement 35 35 100.0
branch n/a
condition n/a
subroutine 17 17 100.0
pod 14 16 87.5
total 66 68 97.0


line stmt bran cond sub pod time code
1             #
2             # Copyright (C) 1999 Eric Bohlman, Loic Dachary
3             #
4             # This program is free software; you can redistribute it and/or modify it
5             # under the terms of the GNU General Public License as published by the
6             # Free Software Foundation; either version 2, or (at your option) any
7             # later version. You may also use, redistribute and/or modify it
8             # under the terms of the Artistic License supplied with your Perl
9             # distribution
10             #
11             # This program is distributed in the hope that it will be useful,
12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14             # GNU General Public License for more details.
15             #
16             # You should have received a copy of the GNU General Public License
17             # along with this program; if not, write to the Free Software
18             # Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19              
20             package Text::Query::Build;
21              
22 2     2   12 use strict;
  2         3  
  2         1231  
23              
24             sub new {
25 7     7 0 16 my $class=shift;
26 7         15 my $self={};
27 7         15 bless $self,$class;
28              
29 7         30 $self->initialize();
30              
31 7         23 return $self;
32             }
33              
34 7     7 0 29 sub initialize {
35             }
36              
37             sub matchstring {
38 39     39 1 53 my($self) = @_;
39              
40 39         305 return $self->{matchstring};
41             }
42              
43             sub build_init {
44 18     18 1 43 my ($self)=@_;
45             }
46              
47             sub build_final_expression {
48 18     18 1 27 my($self, $t1) = @_;
49              
50 18         149 return $self->{matchstring} = $t1;
51             }
52              
53             sub build_expression {
54 11     11 1 17 my($self, $l, $r) = @_;
55              
56 11         71 return "[ or $l $r ]";
57             }
58              
59             sub build_expression_finish {
60 25     25 1 32 my($self, $l) = @_;
61              
62 25         87 return $l;
63             }
64              
65             sub build_conj {
66 10     10 1 14 my($self, $l, $r, $first) = @_;
67              
68 10         43 return "[ and $l $r ]";
69             }
70              
71             sub build_near {
72 2     2 1 6 my($self, $l, $r) = @_;
73              
74 2         24 return "[ near $l $r ]";
75             }
76              
77             sub build_concat {
78 1     1 1 2 my($self, $l, $r) = @_;
79              
80 1         8 return "[ concat $l $r ]";
81             }
82              
83             sub build_negation {
84 3     3 1 6 my($self, $t) = @_;
85              
86 3         12 return "[ not $t ]";
87             }
88              
89             sub build_literal {
90 42     42 1 57 my($self, $t) = @_;
91              
92 42         143 return "[ literal $t ]";
93             }
94              
95             sub build_scope_start {
96 5     5 1 14 my($self) = @_;
97             }
98              
99             sub build_scope_end {
100 5     5 1 7 my($self, $scope, $t) = @_;
101              
102 5         21 return "[ scope '$scope->[0]' $t ]";
103             }
104              
105             sub build_mandatory {
106 3     3 1 3 my($self, $t) = @_;
107              
108 3         9 return "[ mandatory $t ]";
109             }
110              
111             sub build_forbiden {
112 1     1 1 2 my($self, $t) = @_;
113              
114 1         5 return "[ forbiden $t ]";
115             }
116              
117             1;
118              
119             =head1 NAME
120              
121             Text::Query::Build - Base class for query builders
122              
123             =head1 SYNOPSIS
124              
125             package Text::Query::BuildMy;
126              
127             use Text::Query::Build;
128            
129             use vars qw(@ISA);
130              
131             @ISA = qw(Text::Query::Build);
132              
133              
134             =head1 DESCRIPTION
135              
136             This module provides a virtual base class for query builders.
137              
138             Query builders are called by the parser logic. A given set of functions is
139             provided by the builder to match a Boolean logic.
140             All the methods return a scalar corresponding to the code that performs
141             the specified options.
142              
143             Parameters Q1 and Q2 are the same type of scalar as the return values.
144              
145             =head1 METHODS
146              
147             =over 4
148              
149             =item matchstring()
150              
151             Return a string that represent the last built expression. Two identical expressions
152             should generate the same string. This is for testing purpose.
153              
154             =back
155              
156             =head1 CODE-GENERATION METHODS
157              
158             =over 4
159              
160             =item build_init()
161              
162             Called before building the expression. A chance to initialize object data.
163              
164             =item build_final_expression(Q1)
165              
166             Does any final processing to generate code to match a top-level expression.
167             The return value is NOT necessarily of a type that can be passed to
168             the other code-generation methods.
169              
170             =item build_expression(Q1,Q2)
171              
172             Generate code to match C OR C
173              
174             =item build_expression_finish(Q1)
175              
176             Generate any code needed to enclose an expression.
177              
178             =item build_conj(Q1,Q2,F)
179              
180             Generate code needed to match C AND C. F will be true if this is the first
181             time this method is called in a sequence of several conjunctions.
182            
183             =item build_near(Q1,Q2)
184              
185             Generate code needed to match C NEAR C.
186              
187             =item build_concat(Q1,Q2)
188              
189             Generate code needed to match C immediately followed by C.
190              
191             =item build_negation(Q1)
192              
193             Generate code needed to match NOT C.
194              
195             =item build_literal(Q1)
196              
197             Generate code to match C as a literal.
198              
199             =item build_scope_start($scope)
200              
201             Generate code to enter in the C<$scope> query context.
202              
203             =item build_scope_end($scope,Q1)
204              
205             Generate code needed to match C in the C<$scope> context.
206              
207             =item build_mandatory(Q1)
208              
209             Generate code to match C (think + in AltaVista syntax).
210              
211             =item build_forbiden(Q1)
212              
213             Generate code to match NOT C (think - in AltaVista syntax).
214              
215             =back
216              
217             =head1 SEE ALSO
218              
219             Text::Query(3)
220              
221             =head1 AUTHORS
222              
223             Eric Bohlman (ebohlman@netcom.com)
224              
225             Loic Dachary (loic@senga.org)
226              
227             =cut
228              
229             # Local Variables: ***
230             # mode: perl ***
231             # End: ***