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