File Coverage

blib/lib/DBR/Util/Operator.pm
Criterion Covered Total %
statement 33 39 84.6
branch 8 8 100.0
condition n/a
subroutine 16 22 72.7
pod 0 15 0.0
total 57 84 67.8


line stmt bran cond sub pod time code
1             package DBR::Util::Operator;
2              
3 4     4   12215 use strict;
  4         13  
  4         183  
4 4     4   26 use base 'Exporter';
  4         11  
  4         497  
5             our @EXPORT = qw(GT LT GE LE NOT LIKE NOTLIKE BETWEEN NOTBETWEEN AND OR);
6 4     4   726 use DBR::Misc::General; # imported utils
  4         9  
  4         3026  
7              
8             # Object oriented
9             sub new{
10 19     19 0 44 my $package = shift;
11 19         42 my $operator = shift;
12 19         33 my $value = shift;
13              
14 19         56 my $self = [$operator,$value];
15 19         82 bless ( $self, $package );
16 19         121 return ( $self );
17             }
18              
19 45     45 0 232 sub operator {$_[0]->[0]}
20 37     37 0 167 sub value {$_[0]->[1]}
21 70010     70010 0 273293 sub stringify{ 'OP-' . $_[0][0] . ':' . _expandstr( $_[0][1] ) }
22              
23             # EXPORTED:
24              
25 9     9 0 68 sub GT ($) { __PACKAGE__->new('gt', $_[0]) }
26 0     0 0 0 sub LT ($) { __PACKAGE__->new('lt', $_[0]) }
27 0     0 0 0 sub GE ($) { __PACKAGE__->new('ge', $_[0]) }
28 0     0 0 0 sub LE ($) { __PACKAGE__->new('le', $_[0]) }
29 2     2 0 17 sub NOT ($) { __PACKAGE__->new('not', $_[0]) }
30 8     8 0 4026 sub LIKE ($) { __PACKAGE__->new('like',$_[0]) }
31 0     0 0 0 sub NOTLIKE ($) { __PACKAGE__->new('notlike',$_[0]) }
32              
33 0     0 0 0 sub BETWEEN ($$) { __PACKAGE__->new('between', [ $_[0],$_[1] ]) }
34 0     0 0 0 sub NOTBETWEEN ($$) { __PACKAGE__->new('notbetween',[ $_[0],$_[1] ]) }
35              
36             # Yes, having an AND operator is a little silly,
37             # given that AND is the default operation,
38             # but it's necessary to represent some of the more
39             # esoteric queries out there now that OR is in the mix.
40             # A AND (B OR C) is not equivelant to A AND B OR C
41             sub AND {
42 28 100       186 bless ([
43             'And', [ @_ ],
44 11 100   11 0 1184 (scalar ( grep { !(ref($_) eq 'DBR::_LOP') || $_->operator eq 'And' } @_ ) == @_) ? 1 : 0, # calculate only_contains_and
45             ], 'DBR::_LOP');
46             }
47             sub OR {
48 28 100       186 bless ([
49             'Or', [ @_ ],
50 11 100   11 0 43 (scalar ( grep { !(ref($_) eq 'DBR::_LOP') || $_->operator eq 'And' } @_ ) == @_) ? 1 : 0, # calculate only_contains_and
51             ], 'DBR::_LOP' );
52             }
53              
54             package DBR::_LOP;
55 4     4   33 use base 'DBR::Util::Operator';
  4         9  
  4         325  
56 4     4   30 use DBR::Misc::General; # imported utils
  4         9  
  4         551  
57              
58 11     11   45 sub only_contains_and{ $_[0][2] }
59              
60 220000     220000   762450 sub stringify{ 'LOP-' . $_[0][0] . ':' . _expandstr( $_[0][1] ) }
61              
62             1;