File Coverage

blib/lib/Text/Query/BuildAdvancedString.pm
Criterion Covered Total %
statement 42 43 97.6
branch 8 16 50.0
condition 3 5 60.0
subroutine 14 14 100.0
pod 11 11 100.0
total 78 89 87.6


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::BuildAdvancedString;
21              
22 1     1   6 use strict;
  1         2  
  1         40  
23              
24 1     1   5 use vars qw(@ISA $VERSION);
  1         1  
  1         54  
25              
26 1     1   6 use Text::Query::Build;
  1         2  
  1         882  
27              
28             @ISA = qw(Text::Query::Build);
29              
30             sub build_init {
31 14     14 1 42 my($self) = @_;
32             }
33              
34             sub build_final_expression {
35 14     14 1 19 my($self, $t1) = @_;
36 14         17 my($t);
37 14 50       41 $t = ($self->{parseopts}{-case}) ? '' : '(?i)';
38              
39 14         32 $self->{matchstring} = "$t$t1";
40              
41 14         1852 return eval("sub { \$_[0] =~ /$t$t1/s; }")
42             }
43              
44             sub build_expression {
45 7     7 1 13 my($self, $l, $r) = @_;
46             #factor any common "^" out of the disjunction
47             #This really speeds up matching
48 7 50 66     36 if(substr($l,0,1) eq '^' and substr($r,0,1) eq '^') {
49 0         0 return '^(?:'.substr($l,1).'|'.substr($r,1).')';
50             } else {
51 7         56 return "$l|$r";
52             }
53             }
54              
55             sub build_expression_finish {
56 18     18 1 29 my($self, $l) = @_;
57 18         88 return "(?:$l)";
58             }
59              
60             sub build_conj {
61 5     5 1 11 my($self, $l, $r, $first) = @_;
62 5 50       18 $l = "^(?=.*$l)" if($first);
63 5         18 return "$l(?=.*$r)";
64             }
65              
66             sub build_near {
67 1     1 1 3 my($self, $l, $r)=@_;
68 1   50     5 my($t1) = $self->{parseopts}{-near} || '';
69 1         14 return "(?:$l\\s*(?:\\S+\\s+){0,$t1}$r)|(?:$r\\s*(?:\\S+\\s+){0,$t1}$l)";
70             }
71              
72             sub build_concat {
73 1     1 1 3 my($self, $l, $r) = @_;
74 1         9 return "(?:$l\\s*$r)";
75             }
76              
77             sub build_negation {
78 2     2 1 5 my($self, $t) = @_;
79 2         8 return "(?:^(?:(?!$t).)*\$)";
80             }
81              
82             sub build_literal {
83 28     28 1 38 my($self, $t) = @_;
84              
85 28 50       84 if(!$self->{parseopts}{-regexp}) {
86 28         47 $t = quotemeta($t);
87 28         42 $t =~ s/\\\*/\\w*/g;
88             }
89              
90 28 50       88 $t =~ s/\\? +/\\s+/g if(!$self->{parseopts}{-litspace});
91 28 50       75 $t = "\\b$t\\b" if($self->{parseopts}{-whole});
92 28 50       62 $t = "(?:$t)" if($self->{parseopts}{-regexp});
93              
94 28 50       69 warn("build_literal 1 = $t") if($self->{-verbose} > 1);
95              
96 28         95 return $t;
97             }
98              
99             sub build_scope_start {
100 3     3 1 8 my ($self)=@_;
101             }
102              
103             sub build_scope_end {
104 3     3 1 7 my ($self, $scope, $t)=@_;
105              
106 3         9 return $t;
107             }
108              
109             1;
110              
111             __END__