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