| 1 | package OPTIMADE::Filter::ListComparison; | ||||||||||||||||||||||||||||
| 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 | 28 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 28 | my( $class, $operator ) = @_; | |||||||||||||||||||||||||||
| 13 | 28 | return bless { property => undef, | |||||||||||||||||||||||||||
| 14 | operator => $operator, | ||||||||||||||||||||||||||||
| 15 | values => undef }, $class; | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 58 | ▶ | sub property { | ||||||||||||||||||||||||||
|
Subroutine
property: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 58 | my( $self, $property ) = @_; | |||||||||||||||||||||||||||
| 20 | 58 | my $previous_property = $self->{property}; | |||||||||||||||||||||||||||
| 21 | 58 | ▶ | $self->{property} = $property if defined $property; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 58 | return $previous_property; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 26 | ▶ | sub operator { | ||||||||||||||||||||||||||
|
Subroutine
operator: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 26 | my( $self, $operator ) = @_; | |||||||||||||||||||||||||||
| 27 | 26 | my $previous_operator = $self->{operator}; | |||||||||||||||||||||||||||
| 28 | 26 | ▶ | $self->{operator} = $operator if defined $operator; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 26 | return $previous_operator; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 54 | ▶ | sub values { | ||||||||||||||||||||||||||
|
Subroutine
values: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 54 | my( $self, $values ) = @_; | |||||||||||||||||||||||||||
| 34 | 54 | my $previous_values = $self->{values}; | |||||||||||||||||||||||||||
| 35 | 54 | ▶ | $self->{values} = $values if defined $values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 54 | return $previous_values; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 26 | ▶ | sub to_filter { | ||||||||||||||||||||||||||
|
Subroutine
to_filter: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 26 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 41 | 26 | $self->validate; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 26 | my @values; | |||||||||||||||||||||||||||
| 44 | 26 | for my $i (0..$#{$self->{values}}) { | |||||||||||||||||||||||||||
| 45 | 58 | my( $operator, $arg ) = @{$self->{values}[$i]}; | |||||||||||||||||||||||||||
| 46 | 58 | ▶ | if( blessed $arg && $arg->can( 'to_filter' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($arg) and $arg->can("to_filter")
MC/DC50%1/2
builtin::blessed($arg) and $arg->can("to_filter")
builtin::blessed($arg)
$arg->can("to_filter")
Truth table66%2/3
A and B
A= builtin::blessed($arg)B= $arg->can("to_filter")
| |||||||||||||||||||||||||||||
| 47 | 6 | $arg = $arg->to_filter; | |||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 52 | $arg =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||
| 50 | 52 | $arg =~ s/"/\\"/g; | |||||||||||||||||||||||||||
| 51 | 52 | $arg = "\"$arg\""; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 58 | push @values, "$operator $arg"; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | return '(' . join( ' ', $self->{property}->to_filter, | ||||||||||||||||||||||||||||
| 57 | $self->{operator}, | ||||||||||||||||||||||||||||
| 58 | 26 | join( ', ', @values ) ) . ')'; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub to_SQL | ||||||||||||||||||||||||||||
| 62 | 13 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_SQL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 13 | die "no SQL representation\n"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub modify { | ||||||||||||||||||||||||||
|
Subroutine
modify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 2 | my $code = shift; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | $self->property( $self->property->modify( $code, @_ ) ); | |||||||||||||||||||||||||||
| 71 | 6 | $self->{values} = [ map { [ OPTIMADE::Filter::Modifiable::modify( $_->[0], $code, @_ ), | |||||||||||||||||||||||||||
| 72 | OPTIMADE::Filter::Modifiable::modify( $_->[1], $code, @_ ) ] } | ||||||||||||||||||||||||||||
| 73 | 2 | @{$self->{values}} ]; | |||||||||||||||||||||||||||
| 74 | 2 | return $code->( $self, @_ ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub validate | ||||||||||||||||||||||||||||
| 78 | 26 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=4 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 26 | ▶ | if( !$self->property ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | die 'property undefined for OPTIMADE::Filter::ListComparison'; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 26 | ▶ | if( !$self->operator ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | die 'operator undefined for OPTIMADE::Filter::ListComparison'; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 26 | ▶ | if( !$self->values ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | die 'values undefined for OPTIMADE::Filter::ListComparison'; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | 1; | |||||||||||||||||||||||||||