blib/lib/OPTIMADE/Filter/AndOr.pm

filter: Statementstmt 70.1% 68 / 97 Branchbran 44.1% 15 / 34 Conditioncond 66.6% 8 / 12 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 10 totaltotal 59.7% 104 / 174 CC 24 SCAR 19.5
CC
24
Cov
64%
to_SQL
13.8
push_operand
6.0
unshift_operand
6.0
CRAP 7.0
« blib/lib/OPTIMADE/Filter/Comparison.pm ↑ Summary lib/OPTIMADE/Filter/Parser.yp »
1 package OPTIMADE::Filter::AndOr;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use parent 'OPTIMADE::Filter::Modifiable';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our $VERSION = '0.11.0'; # VERSION
10  
11 142 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod undocumented
12 142 my $class = shift;
13 142 my $operator;
14 my @operands;
15  
16 142 ▶ if( @_ == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 0 142 142
elsif (@_ == 3) { } 142 0 142
17 0 @operands = @_;
18 } elsif( @_ == 3 ) {
19 142 ( $operands[0], $operator, $operands[1] ) = @_;
20 }
21 142 return bless { operands => \@operands,
22 operator => $operator }, $class;
23 }
24  
25 222 ▶sub operator {
Subroutine operator: called CC=2 SCAR=7.0
Pod undocumented
26 222 my( $self, $operator ) = @_;
27 222 my $previous_operator = $self->{operator};
28 222 ▶ $self->{operator} = $operator if defined $operator;
Branch: 1 branch
BranchTrueFalseTotal
if defined $operator 0 222 222
29 222 return $previous_operator;
30 }
31  
32 sub push_operand
33 0 ▶{
Subroutine push_operand: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my( $self, $operand ) = @_;
35 0 ▶ die 'attempt to insert more than two operands' if @{$self->{operands}} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"operands"};} >= 2 0 0 0
36 0 push @{$self->{operands}}, $operand;
37 }
38  
39 sub unshift_operand
40 0 ▶{
Subroutine unshift_operand: not called CC=2 SCAR=17.9
Pod undocumented
41 0 my( $self, $operand ) = @_;
42 0 ▶ die 'attempt to insert more than two operands' if @{$self->{operands}} >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"operands"};} >= 2 0 0 0
43 0 unshift @{$self->{operands}}, $operand;
44 }
45  
46 sub left
47 0 ▶{
Subroutine left: not called CC=2 SCAR=17.9
Pod undocumented
48 0 my( $self, $operand ) = @_;
49 0 my $previous_operand = $self->{operands}[0];
50 0 ▶ $self->{operands}[0] = $operand if defined $operand;
Branch: 1 branch
BranchTrueFalseTotal
if defined $operand 0 0 0
51 0 return $previous_operand;
52 }
53  
54 sub right
55 0 ▶{
Subroutine right: not called CC=2 SCAR=17.9
Pod undocumented
56 0 my( $self, $operand ) = @_;
57 0 my $previous_operand = $self->{operands}[1];
58 0 ▶ $self->{operands}[1] = $operand if defined $operand;
Branch: 1 branch
BranchTrueFalseTotal
if defined $operand 0 0 0
59 0 return $previous_operand;
60 }
61  
62 sub to_filter
63 140 ▶{
Subroutine to_filter: called CC=4 SCAR=15.0
Pod undocumented
64 140 my( $self ) = @_;
65 140 $self->validate;
66  
67 140 my $operator = $self->{operator};
68 140 my @operands;
69 140 for my $i (0..$#{$self->{operands}}) {
70 280 my $arg = $self->{operands}[$i];
71 280 ▶ if( blessed $arg && $arg->can( 'to_filter' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->can('to_filter')) { } 280 0 280
Condition33%1/3
builtin::blessed($arg) and $arg->can("to_filter")
!ll&&!rl&&r
00280
MC/DC0%0/2
builtin::blessed($arg) and $arg->can("to_filter")
builtin::blessed($arg) $arg->can("to_filter")
Truth table33%1/3
A and B
A= builtin::blessed($arg)B= $arg->can("to_filter")
ABresult
0X0
100
111
72 280 $arg = $arg->to_filter;
73 } else {
74 0 $arg =~ s/\\/\\\\/g;
75 0 $arg =~ s/"/\\"/g;
76 0 $arg = "\"$arg\"";
77 }
78 280 push @operands, $arg;
79 }
80  
81 140 return "($operands[0] $operator $operands[1])";
82 }
83  
84 sub to_SQL
85 70 ▶{
Subroutine to_SQL: called CC=12 SCAR=26.2
Pod undocumented
86 70 my( $self, $options ) = @_;
87 70 $self->validate;
88  
89 70 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 0 70 70
90 my( $delim, $flatten, $placeholder ) = (
91 $options->{delim},
92 $options->{flatten},
93 $options->{placeholder},
94 70 );
95 70 ▶ $delim = "'" unless $delim;
Branch: 1 branch
BranchTrueFalseTotal
unless $delim 70 0 70
96  
97 70 my $operator = $self->{operator};
98 70 my @operands;
99 my @values;
100 70 for my $i (0..$#{$self->{operands}}) {
101 140 my $arg = $self->{operands}[$i];
102 140 ▶ if( blessed $arg && $arg->can( 'to_SQL' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->can('to_SQL')) { } 140 0 140
Condition33%1/3
builtin::blessed($arg) and $arg->can("to_SQL")
!ll&&!rl&&r
00140
MC/DC0%0/2
builtin::blessed($arg) and $arg->can("to_SQL")
builtin::blessed($arg) $arg->can("to_SQL")
Truth table33%1/3
A and B
A= builtin::blessed($arg)B= $arg->can("to_SQL")
ABresult
0X0
100
111
103 140 my $values = [];
104 140 eval { ( $arg, $values ) = $arg->to_SQL( $options ) };
105 140 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 24 116 140
106 24 chomp $@;
107 24 $arg = "<$@>";
108 }
109 140 ▶ if( $self->{operands}[$i]->isa( OPTIMADE::Filter::AndOr:: ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr") and !$flatten || $self->operator ne $self->{"operands"}[$i]->operator) 41 99 140
Condition100%6/6
$self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr") and !$flatten || $self->operator ne $self->{"operands"}[$i]->operator
!ll&&!rl&&r
94541
not $flatten or $self->operator ne $self->{"operands"}[$i]->operator
l!l&&r!l&&!r
4015
MC/DC100%3/3
$self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr") and !$flatten || $self->operator ne $self->{"operands"}[$i]->operator
$self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr") not $flatten $self->operator ne $self->{"operands"}[$i]->operator
Truth table100%4/4
A and not(B) or C
A= $self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr")B= not $flattenC= $self->operator ne $self->{"operands"}[$i]->operator
ABCresult
0XX0
1000
11X1
1011
110 (!$flatten || $self->operator ne $self->{operands}[$i]->operator) ) {
111 41 $arg = "($arg)";
112 }
113 140 push @values, @$values;
114 } else {
115 0 push @values, $arg;
116 0 ▶ if( $placeholder ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($placeholder) { } 0 0 0
117 0 $arg = $placeholder;
118 } else {
119 0 $arg =~ s/"/""/g;
120 0 $arg = "\"$arg\"";
121 }
122 }
123 140 push @operands, $arg;
124 }
125  
126 70 ▶ if( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 50 20 70
127 50 return ( "$operands[0] $operator $operands[1]", \@values );
128 } else {
129 20 return "$operands[0] $operator $operands[1]";
130 }
131 }
132  
133 sub modify
134 2 ▶{
Subroutine modify: called CC=1 SCAR=0.0
Pod undocumented
135 2 my $self = shift;
136 2 my $code = shift;
137  
138 4 $self->{operands} = [ map { OPTIMADE::Filter::Modifiable::modify( $_, $code, @_ ) }
139 2 @{$self->{operands}} ];
140 2 return $code->( $self, @_ );
141 }
142  
143 sub validate
144 210 ▶{
Subroutine validate: called CC=3 SCAR=12.7
Pod undocumented
145 210 my $self = shift;
146  
147 210 ▶ if( @{$self->{operands}} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"operands"};} != 2) 0 210 210
148 die 'number of operands for OPTIMADE::Filter::AndOr must be 2, ' .
149 0 'got ' . @{$self->{operands}};
150 }
151 210 ▶ die 'operator undefined for OPTIMADE::Filter::AndOr' if !$self->operator;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->operator 0 210 210
152 }
153  
154 5 1;
« blib/lib/OPTIMADE/Filter/Comparison.pm ↑ Summary lib/OPTIMADE/Filter/Parser.yp »