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