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