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