blib/lib/OPTIMADE/Filter/AndOr.pm

filter: Statementstmt 70.1% 68 / 97 Branchbran 44.1% 15 / 34 Conditioncond 66.6% 8 / 12 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 10 totaltotal 59.2% 103 / 174 SCAR 39.5
CC
24
Cov
64%
to_SQL
13.8
push_operand
6.0
unshift_operand
6.0
CRAP 51.7
↑ Summary blib/lib/OPTIMADE/Filter/Comparison.pm »
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.10.2'; # VERSION
10  
11 sub new {
12 130 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.8
Pod undocumented
13 130 my $operator;
14 my @operands;
15  
16 130 ▶ if( @_ == 2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 2) { } 0 130 130
elsif (@_ == 3) { } 130 0 130
17 0 @operands = @_;
18 } elsif( @_ == 3 ) {
19 130 ( $operands[0], $operator, $operands[1] ) = @_;
20 }
21 130 return bless { operands => \@operands,
22 operator => $operator }, $class;
23 }
24  
25 sub operator {
26 204 ▶ my( $self, $operator ) = @_;
Subroutine operator: called CC=2 SCAR=7.0
Pod undocumented
27 204 my $previous_operator = $self->{operator};
28 204 ▶ $self->{operator} = $operator if defined $operator;
Branch: 1 branch
BranchTrueFalseTotal
if defined $operator 0 204 204
29 204 return $previous_operator;
30 }
31  
32 sub push_operand
33 {
34 0 ▶ my( $self, $operand ) = @_;
Subroutine push_operand: not called CC=2 SCAR=17.9
Pod undocumented
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 {
41 0 ▶ my( $self, $operand ) = @_;
Subroutine unshift_operand: not called CC=2 SCAR=17.9
Pod undocumented
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 {
48 0 ▶ my( $self, $operand ) = @_;
Subroutine left: not called CC=2 SCAR=17.9
Pod undocumented
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 {
56 0 ▶ my( $self, $operand ) = @_;
Subroutine right: not called CC=2 SCAR=17.9
Pod undocumented
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 {
64 128 ▶ my( $self ) = @_;
Subroutine to_filter: called CC=4 SCAR=15.0
Pod undocumented
65 128 $self->validate;
66  
67 128 my $operator = $self->{operator};
68 128 my @operands;
69 128 for my $i (0..$#{$self->{operands}}) {
70 256 my $arg = $self->{operands}[$i];
71 256 ▶ if( blessed $arg && $arg->can( 'to_filter' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->can('to_filter')) { } 256 0 256
Condition33%1/3
builtin::blessed($arg) and $arg->can("to_filter")
!ll&&!rl&&r
00256
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 256 $arg = $arg->to_filter;
73 } else {
74 0 $arg =~ s/\\/\\\\/g;
75 0 $arg =~ s/"/\\"/g;
76 0 $arg = "\"$arg\"";
77 }
78 256 push @operands, $arg;
79 }
80  
81 128 return "($operands[0] $operator $operands[1])";
82 }
83  
84 sub to_SQL
85 {
86 64 ▶ my( $self, $options ) = @_;
Subroutine to_SQL: called CC=12 SCAR=26.2
Pod undocumented
87 64 $self->validate;
88  
89 64 ▶ $options = {} unless $options;
Branch: 1 branch
BranchTrueFalseTotal
unless $options 0 64 64
90 my( $delim, $flatten, $placeholder ) = (
91 $options->{delim},
92 $options->{flatten},
93 $options->{placeholder},
94 64 );
95 64 ▶ $delim = "'" unless $delim;
Branch: 1 branch
BranchTrueFalseTotal
unless $delim 64 0 64
96  
97 64 my $operator = $self->{operator};
98 64 my @operands;
99 my @values;
100 64 for my $i (0..$#{$self->{operands}}) {
101 128 my $arg = $self->{operands}[$i];
102 128 ▶ if( blessed $arg && $arg->can( 'to_SQL' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->can('to_SQL')) { } 128 0 128
Condition33%1/3
builtin::blessed($arg) and $arg->can("to_SQL")
!ll&&!rl&&r
00128
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 128 my $values = [];
104 128 eval { ( $arg, $values ) = $arg->to_SQL( $options ) };
105 128 ▶ if( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 14 114 128
106 14 chomp $@;
107 14 $arg = "<$@>";
108 }
109 128 ▶ 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) 39 89 128
Condition100%6/6
$self->{"operands"}[$i]->isa("OPTIMADE::Filter::AndOr") and !$flatten || $self->operator ne $self->{"operands"}[$i]->operator
!ll&&!rl&&r
84431
not $flatten or $self->operator ne $self->{"operands"}[$i]->operator
l!l&&r!l&&!r
3815
MC/DC66%2/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 table75%3/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 39 $arg = "($arg)";
112 }
113 128 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 128 push @operands, $arg;
124 }
125  
126 64 ▶ if( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 48 16 64
127 48 return ( "$operands[0] $operator $operands[1]", \@values );
128 } else {
129 16 return "$operands[0] $operator $operands[1]";
130 }
131 }
132  
133 sub modify
134 {
135 2 ▶ my $self = shift;
Subroutine modify: called CC=1 SCAR=0.0
Pod undocumented
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 {
145 192 ▶ my $self = shift;
Subroutine validate: called CC=3 SCAR=12.7
Pod undocumented
146  
147 192 ▶ if( @{$self->{operands}} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"operands"};} != 2) 0 192 192
148 die 'number of operands for OPTIMADE::Filter::AndOr must be 2, ' .
149 0 'got ' . @{$self->{operands}};
150 }
151 192 ▶ die 'operator undefined for OPTIMADE::Filter::AndOr' if !$self->operator;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->operator 0 192 192
152 }
153  
154 5 1;
↑ Summary blib/lib/OPTIMADE/Filter/Comparison.pm »