line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPTIMADE::Filter::Zip; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
35
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
145
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
131
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
24
|
use parent 'OPTIMADE::Filter::Modifiable'; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
296
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
3719
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
12
|
|
|
12
|
0
|
25
|
my( $class ) = @_; |
12
|
12
|
|
|
|
|
54
|
return bless { properties => [], |
13
|
|
|
|
|
|
|
operator => undef, |
14
|
|
|
|
|
|
|
values => [] }, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub push_property { |
18
|
14
|
|
|
14
|
0
|
27
|
my( $self, $property ) = @_; |
19
|
14
|
|
|
|
|
23
|
push @{$self->{properties}}, $property; |
|
14
|
|
|
|
|
43
|
|
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub unshift_property { |
23
|
12
|
|
|
12
|
0
|
24
|
my( $self, $property ) = @_; |
24
|
12
|
|
|
|
|
19
|
unshift @{$self->{properties}}, $property; |
|
12
|
|
|
|
|
31
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub operator { |
28
|
24
|
|
|
24
|
0
|
48
|
my( $self, $operator ) = @_; |
29
|
24
|
|
|
|
|
44
|
my $previous_operator = $self->{operator}; |
30
|
24
|
100
|
|
|
|
60
|
$self->{operator} = $operator if defined $operator; |
31
|
24
|
|
|
|
|
53
|
return $previous_operator; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub values { |
35
|
24
|
|
|
24
|
0
|
45
|
my( $self, $values ) = @_; |
36
|
24
|
|
|
|
|
38
|
my $previous_values = $self->{values}; |
37
|
24
|
100
|
|
|
|
49
|
$self->{values} = $values if defined $values; |
38
|
24
|
|
|
|
|
51
|
return $previous_values; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub to_filter { |
42
|
12
|
|
|
12
|
0
|
961
|
my( $self ) = @_; |
43
|
12
|
|
|
|
|
31
|
$self->validate; |
44
|
|
|
|
|
|
|
|
45
|
12
|
|
|
|
|
19
|
my @zip_list; |
46
|
12
|
|
|
|
|
18
|
foreach my $zip (@{$self->{values}}) { |
|
12
|
|
|
|
|
27
|
|
47
|
22
|
|
|
|
|
30
|
my @zip; |
48
|
22
|
|
|
|
|
43
|
for my $i (0..$#$zip) { |
49
|
50
|
|
|
|
|
61
|
my( $operator, $arg ) = @{$zip->[$i]}; |
|
50
|
|
|
|
|
96
|
|
50
|
50
|
50
|
33
|
|
|
124
|
if( blessed $arg && $arg->can( 'to_filter' ) ) { |
51
|
0
|
|
|
|
|
0
|
$arg = $arg->to_filter; |
52
|
|
|
|
|
|
|
} else { |
53
|
50
|
|
|
|
|
84
|
$arg =~ s/\\/\\\\/g; |
54
|
50
|
|
|
|
|
69
|
$arg =~ s/"/\\"/g; |
55
|
50
|
|
|
|
|
76
|
$arg = "\"$arg\""; |
56
|
|
|
|
|
|
|
} |
57
|
50
|
|
|
|
|
102
|
push @zip, "$operator $arg"; |
58
|
|
|
|
|
|
|
} |
59
|
22
|
|
|
|
|
67
|
push @zip_list, join( ' : ', @zip ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
26
|
|
|
|
|
61
|
return '(' . join( ':', map { $_->to_filter } @{$self->{properties}} ) . |
|
12
|
|
|
|
|
24
|
|
63
|
12
|
|
|
|
|
24
|
' ' . $self->{operator} . ' ' . |
64
|
|
|
|
|
|
|
join( ', ', @zip_list ) . ')'; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub to_SQL |
68
|
|
|
|
|
|
|
{ |
69
|
6
|
|
|
6
|
0
|
36
|
die "no SQL representation\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub modify |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
75
|
0
|
|
|
|
|
0
|
my $code = shift; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
$self->{properties} = [ map { $_->modify( $code, @_ ) } @{$self->{properties}} ]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
78
|
0
|
|
|
|
|
0
|
$self->{values} = [ map { [ OPTIMADE::Filter::Modifiable::modify( $_->[0], $code, @_ ), |
79
|
|
|
|
|
|
|
OPTIMADE::Filter::Modifiable::modify( $_->[1], $code, @_ ) ] } |
80
|
0
|
|
|
|
|
0
|
@{$self->{values}} ]; |
|
0
|
|
|
|
|
0
|
|
81
|
0
|
|
|
|
|
0
|
return $code->( $self, @_ ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub validate |
85
|
|
|
|
|
|
|
{ |
86
|
12
|
|
|
12
|
0
|
19
|
my $self = shift; |
87
|
|
|
|
|
|
|
|
88
|
12
|
50
|
|
|
|
29
|
if( !$self->{properties} ) { |
89
|
0
|
|
|
|
|
0
|
die 'properties undefined for OPTIMADE::Filter::Zip'; |
90
|
|
|
|
|
|
|
} |
91
|
12
|
50
|
|
|
|
21
|
if( !$self->operator ) { |
92
|
0
|
|
|
|
|
0
|
die 'operator undefined for OPTIMADE::Filter::Zip'; |
93
|
|
|
|
|
|
|
} |
94
|
12
|
50
|
|
|
|
27
|
if( !$self->values ) { |
95
|
0
|
|
|
|
|
|
die 'values undefined for OPTIMADE::Filter::Zip'; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |