| 1 | package OPTIMADE::Filter::Zip; | ||||||||||||||||||||||||||||
| 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 List::Util qw(any); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.11.0'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 16 | my( $class ) = @_; | |||||||||||||||||||||||||||
| 14 | 16 | return bless { properties => [], | |||||||||||||||||||||||||||
| 15 | operator => undef, | ||||||||||||||||||||||||||||
| 16 | values => [] }, $class; | ||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 18 | ▶ | sub push_property { | ||||||||||||||||||||||||||
|
Subroutine
push_property: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 18 | my( $self, $property ) = @_; | |||||||||||||||||||||||||||
| 21 | 18 | push @{$self->{properties}}, $property; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 16 | ▶ | sub unshift_property { | ||||||||||||||||||||||||||
|
Subroutine
unshift_property: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 16 | my( $self, $property ) = @_; | |||||||||||||||||||||||||||
| 26 | 16 | unshift @{$self->{properties}}, $property; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 32 | ▶ | sub operator { | ||||||||||||||||||||||||||
|
Subroutine
operator: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 32 | my( $self, $operator ) = @_; | |||||||||||||||||||||||||||
| 31 | 32 | my $previous_operator = $self->{operator}; | |||||||||||||||||||||||||||
| 32 | 32 | ▶ | $self->{operator} = $operator if defined $operator; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 32 | return $previous_operator; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 48 | ▶ | sub values { | ||||||||||||||||||||||||||
|
Subroutine
values: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 48 | my( $self, $values ) = @_; | |||||||||||||||||||||||||||
| 38 | 48 | my $previous_values = $self->{values}; | |||||||||||||||||||||||||||
| 39 | 48 | ▶ | $self->{values} = $values if defined $values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 48 | return $previous_values; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 16 | ▶ | sub to_filter { | ||||||||||||||||||||||||||
|
Subroutine
to_filter: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 16 | my( $self ) = @_; | |||||||||||||||||||||||||||
| 45 | 16 | $self->validate; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 16 | my @zip_list; | |||||||||||||||||||||||||||
| 48 | 16 | foreach my $zip (@{$self->{values}}) { | |||||||||||||||||||||||||||
| 49 | 26 | my @zip; | |||||||||||||||||||||||||||
| 50 | 26 | for my $i (0..$#$zip) { | |||||||||||||||||||||||||||
| 51 | 58 | my( $operator, $arg ) = @{$zip->[$i]}; | |||||||||||||||||||||||||||
| 52 | 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")
| |||||||||||||||||||||||||||||
| 53 | 2 | $arg = $arg->to_filter; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | 56 | $arg =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||
| 56 | 56 | $arg =~ s/"/\\"/g; | |||||||||||||||||||||||||||
| 57 | 56 | $arg = "\"$arg\""; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 58 | push @zip, "$operator $arg"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 26 | push @zip_list, join( ' : ', @zip ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 34 | return '(' . join( ':', map { $_->to_filter } @{$self->{properties}} ) . | |||||||||||||||||||||||||||
| 65 | 16 | ' ' . $self->{operator} . ' ' . | |||||||||||||||||||||||||||
| 66 | join( ', ', @zip_list ) . ')'; | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | sub to_SQL | ||||||||||||||||||||||||||||
| 70 | 8 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_SQL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 8 | die "no SQL representation\n"; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub modify | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
modify: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 0 | my $code = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->{properties} = [ map { $_->modify( $code, @_ ) } @{$self->{properties}} ]; | |||||||||||||||||||||||||||
| 80 | 0 | $self->{values} = [ map { [ OPTIMADE::Filter::Modifiable::modify( $_->[0], $code, @_ ), | |||||||||||||||||||||||||||
| 81 | OPTIMADE::Filter::Modifiable::modify( $_->[1], $code, @_ ) ] } | ||||||||||||||||||||||||||||
| 82 | 0 | @{$self->{values}} ]; | |||||||||||||||||||||||||||
| 83 | 0 | return $code->( $self, @_ ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub validate | ||||||||||||||||||||||||||||
| 87 | 16 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 88 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 16 | ▶ | if( !$self->{properties} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | die 'properties undefined for OPTIMADE::Filter::Zip'; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 16 | ▶ | if( !$self->operator ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | die 'operator undefined for OPTIMADE::Filter::Zip'; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 16 | ▶ | if( !$self->values ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | die 'values undefined for OPTIMADE::Filter::Zip'; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 16 | ▶ | if( any { scalar @$_ != scalar @{$self->{properties}} } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 16 | @{$self->values} ) { | |||||||||||||||||||||||||||
| 101 | 0 | die 'different number of properties and values for OPTIMADE::Filter::Zip'; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 5 | 1; | |||||||||||||||||||||||||||