TermNode.pm

filter: Statementstmt 100% 69 / 69 Branchbran 90.0% 18 / 20 Conditioncond 66.6% 8 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 14 / 14 Podpod 88.8% 8 / 9 totaltotal 91.6% 121 / 132 CC 16 SCAR 11.4
CC
16
Cov
94%
toLucene
6.0
new
3.5
toSwish
3.0
CRAP 3.1
« Parser.pm ↑ Summary ModifierSet.pm »
1 package CQL::TermNode;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use base qw( CQL::Node );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use CQL::Utils qw( indent xq renderPrefixes );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 CQL::TermNode - represents a terminal Node in a CQL Parse Tree
12  
13 =head1 SYNOPSIS
14  
15 =head1 DESCRIPTION
16  
17 CQL::TermNode represents a terminal in a CQL parse tree. A term node
18 consists of the string itself with optional qualifier string and relation.
19 Examples could include:
20  
21 =over 4
22  
23 =item * george
24  
25 =item * dc.creator=george
26  
27 =back
28  
29 =head1 METHODS
30  
31 =head2 new()
32  
33 The constructor which has must have at least a term attribute, and
34 can also include optional qualifier and modifier terms.
35  
36 =cut
37  
38 96 ▶sub new {
Subroutine new: called CC=3 SCAR=12.5
Pod documented
39 96 my ($class,%args) = @_;
40 96 ▶ croak( "must supply term parameter" ) if ! exists( $args{term} );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"term"} 0 96 96
41 96 ▶ return bless \%args, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0960
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
42 }
43  
44 =head2 getQualifier()
45  
46 Get the qualifier in the terminal.
47  
48 =cut
49  
50 204 ▶sub getQualifier {
Subroutine getQualifier: called CC=1 SCAR=0.0
Pod documented
51 204 return shift->{qualifier};
52 }
53  
54 =head2 getRelation()
55  
56 Get the relation in the terminal.
57  
58 =cut
59  
60 213 ▶sub getRelation {
Subroutine getRelation: called CC=1 SCAR=0.0
Pod documented
61 213 return shift->{relation};
62 }
63  
64 =head2 getTerm()
65  
66 Get the actual term string in the terminal.
67  
68 =cut
69  
70 206 ▶sub getTerm {
Subroutine getTerm: called CC=1 SCAR=0.0
Pod documented
71 206 return shift->{term};
72 }
73  
74 =head2 toCQL()
75  
76 Returns a CQL representation of the terminal node.
77  
78 =cut
79  
80 163 ▶sub toCQL {
Subroutine toCQL: called CC=3 SCAR=11.0
Pod documented
81 163 my $self = shift;
82 163 my $qualifier = maybeQuote( $self->getQualifier() );
83 163 my $term = maybeQuote( $self->getTerm() );
84 163 my $relation = $self->getRelation();
85  
86 163 my $cql;
87 163 ▶ if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualifier and not $qualifier =~ /srw\.serverChoice/i) { } 46 117 163
Condition100%3/3
$qualifier and not $qualifier =~ /srw\.serverChoice/i
!ll&&!rl&&r
1110646
MC/DC100%2/2
$qualifier and not $qualifier =~ /srw\.serverChoice/i
$qualifier not $qualifier =~ /srw\.serverChoice/i
Truth table100%3/3
A and not(B)
A= $qualifierB= not $qualifier =~ /srw\.serverChoice/i
ABresult
0X0
100
111
88 46 $cql = join( ' ', $qualifier, $relation->toCQL(), $term);
89 } else {
90 117 $cql = $term;
91 }
92 163 return $cql;
93 }
94  
95 =head2 toSwish()
96  
97 =cut
98  
99 14 ▶sub toSwish {
Subroutine toSwish: called CC=3 SCAR=11.0
Pod documented
100 14 my $self = shift;
101 14 my $qualifier = maybeQuote( $self->getQualifier() );
102 14 my $term = maybeQuote( $self->getTerm() );
103 14 my $relation = $self->getRelation();
104 14 my $swish;
105 14 ▶ if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualifier and not $qualifier =~ /srw\.serverChoice/i) { } 2 12 14
Condition66%2/3
$qualifier and not $qualifier =~ /srw\.serverChoice/i
!ll&&!rl&&r
0122
MC/DC50%1/2
$qualifier and not $qualifier =~ /srw\.serverChoice/i
$qualifier not $qualifier =~ /srw\.serverChoice/i
Truth table66%2/3
A and not(B)
A= $qualifierB= not $qualifier =~ /srw\.serverChoice/i
ABresult
0X0
100
111
106 2 $swish = join( ' ', $qualifier, $relation->toSwish(), $term );
107 } else {
108 12 $swish = $term;
109 }
110 13 return $swish;
111 }
112  
113 =head2 toXCQL()
114  
115 =cut
116  
117 6 ▶sub toXCQL {
Subroutine toXCQL: called CC=3 SCAR=11.0
Pod documented
118 6 my ($self,$level,@prefixes) = @_;
119 6 ▶ $level = 0 unless $level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level 2 4 6
120 6 my $xml =
121 indent($level) . "<searchClause>\n" .
122 renderPrefixes($level+1,@prefixes) .
123 indent($level+1) . "<index>".xq($self->getQualifier())."</index>\n";
124 6 ▶ if ( $self->getRelation() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getRelation) 2 4 6
125 2 $xml .= $self->getRelation()->toXCQL($level+1);
126 }
127 $xml .=
128 6 indent($level+1) . "<term>" . xq($self->getTerm()) . "</term>\n" .
129 indent($level) . "</searchClause>\n";
130 6 return $self->addNamespace( $level, $xml );
131 }
132  
133 =head2 toLucene()
134  
135 =cut
136  
137 19 ▶sub toLucene {
Subroutine toLucene: called CC=6 SCAR=17.9
Pod documented
138 19 my $self = shift;
139 19 my $qualifier = maybeQuote( $self->getQualifier() );
140 19 my $term = maybeQuote( $self->getTerm() );
141 19 my $relation = $self->getRelation();
142  
143 19 my $query;
144 19 ▶ if ( $qualifier and $qualifier !~ /srw\.serverChoice/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qualifier and not $qualifier =~ /srw\.serverChoice/i) { } 3 16 19
Condition66%2/3
$qualifier and not $qualifier =~ /srw\.serverChoice/i
!ll&&!rl&&r
0163
MC/DC50%1/2
$qualifier and not $qualifier =~ /srw\.serverChoice/i
$qualifier not $qualifier =~ /srw\.serverChoice/i
Truth table66%2/3
A and not(B)
A= $qualifierB= not $qualifier =~ /srw\.serverChoice/i
ABresult
0X0
100
111
145 3 my $base = $relation->getBase();
146 3 my @modifiers = $relation->getModifiers();
147  
148 3 foreach my $m ( @modifiers ) {
149 1 ▶ if( $m->[ 1 ] eq 'fuzzy' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->[1] eq "fuzzy") 1 0 1
150 1 $term = "$term~";
151 }
152 }
153  
154 3 ▶ if( $base eq '=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base eq '=') { } 2 1 3
155 2 $base = ':';
156 }
157 else {
158 1 croak( "Lucene doesn't support relations other than '='" );
159 }
160 2 return "$qualifier$base$term";
161 }
162 else {
163 16 return $term;
164 }
165 }
166  
167 392 ▶sub maybeQuote {
Subroutine maybeQuote: called CC=3 SCAR=11.0
Pod undocumented
168 392 my $str = shift;
169 392 ▶ return if ! defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 11 381 392
170 381 ▶ if ( $str =~ m|[" \t=<>/()]| ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ m[[" \t=<>/()]]) 39 342 381
171 39 $str =~ s/"/\\"/g;
172 39 $str = qq("$str");
173 }
174 381 return $str;
175 }
176  
177 10 1;
« Parser.pm ↑ Summary ModifierSet.pm »