| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OPTIMADE::Filter::Property; |
|
2
|
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
772
|
use strict; |
|
|
7
|
|
|
|
|
16
|
|
|
|
7
|
|
|
|
|
187
|
|
|
4
|
7
|
|
|
7
|
|
32
|
use warnings; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
191
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
422
|
use parent 'OPTIMADE::Filter::Modifiable'; |
|
|
7
|
|
|
|
|
282
|
|
|
|
7
|
|
|
|
|
29
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
437
|
use Scalar::Util qw(blessed); |
|
|
7
|
|
|
|
|
21
|
|
|
|
7
|
|
|
|
|
1059
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
2498
|
|
|
2498
|
|
5537
|
use overload '@{}' => sub { return $_[0]->{name} }, |
|
11
|
505
|
|
|
505
|
|
61849
|
'""' => sub { return $_[0]->to_filter }, |
|
12
|
0
|
|
|
0
|
|
0
|
'==' => sub { return $_[0]->_eq( $_[1] ) }, |
|
13
|
7
|
|
|
7
|
|
7402
|
'eq' => sub { return $_[0]->_eq( $_[1] ) }; |
|
|
7
|
|
|
1
|
|
5981
|
|
|
|
7
|
|
|
|
|
120
|
|
|
|
1
|
|
|
|
|
173
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $identifier_re = q/([a-z_][a-z0-9_]*)/; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
239
|
|
|
239
|
0
|
499
|
my $class = shift; |
|
19
|
239
|
|
|
|
|
999
|
return bless { name => \@_ }, $class; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub to_filter |
|
23
|
|
|
|
|
|
|
{ |
|
24
|
735
|
|
|
735
|
0
|
1284
|
my( $self ) = @_; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Validate |
|
27
|
735
|
|
|
|
|
1553
|
$self->validate; |
|
28
|
735
|
|
|
|
|
1365
|
for my $name (@$self) { |
|
29
|
744
|
|
|
|
|
1381
|
my $lc_name = lc $name; |
|
30
|
744
|
100
|
|
|
|
3914
|
next if $lc_name =~ /^$identifier_re$/; |
|
31
|
1
|
|
|
|
|
11
|
die "name '$lc_name' does not match identifier syntax: $identifier_re"; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
734
|
|
|
|
|
1569
|
return join '.', map { lc } @$self; |
|
|
741
|
|
|
|
|
3384
|
|
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub to_SQL |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
92
|
|
|
92
|
0
|
180
|
my( $self, $options ) = @_; |
|
40
|
|
|
|
|
|
|
|
|
41
|
92
|
100
|
|
|
|
196
|
$options = {} unless $options; |
|
42
|
|
|
|
|
|
|
my( $delim, $placeholder ) = ( |
|
43
|
|
|
|
|
|
|
$options->{delim}, |
|
44
|
|
|
|
|
|
|
$options->{placeholder}, |
|
45
|
92
|
|
|
|
|
176
|
); |
|
46
|
92
|
50
|
|
|
|
189
|
$delim = "'" unless $delim; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Validate |
|
49
|
92
|
|
|
|
|
201
|
$self->validate; |
|
50
|
92
|
50
|
|
|
|
160
|
if( @$self > 2 ) { |
|
51
|
0
|
|
|
|
|
0
|
die 'no SQL representation for properties of more than two ' . |
|
52
|
|
|
|
|
|
|
"identifiers\n"; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Construct the SQL |
|
56
|
92
|
|
|
|
|
167
|
my $sql = join '.', map { "${delim}$_${delim}" } @$self; |
|
|
94
|
|
|
|
|
301
|
|
|
57
|
|
|
|
|
|
|
|
|
58
|
92
|
100
|
|
|
|
202
|
if( wantarray ) { |
|
59
|
91
|
|
|
|
|
304
|
return ( $sql, [] ); |
|
60
|
|
|
|
|
|
|
} else { |
|
61
|
1
|
|
|
|
|
5
|
return $sql; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub modify |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
7
|
|
|
7
|
0
|
18
|
my $self = shift; |
|
68
|
7
|
|
|
|
|
10
|
my $code = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
7
|
|
|
|
|
18
|
return $code->( $self, @_ ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub validate |
|
74
|
|
|
|
|
|
|
{ |
|
75
|
827
|
|
|
827
|
0
|
1257
|
my $self = shift; |
|
76
|
827
|
50
|
|
|
|
1534
|
die 'name undefined for OPTIMADE::Filter::Property' if !@$self; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _eq |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
1
|
|
|
1
|
|
3
|
my( $a, $b ) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
6
|
return '' if !blessed( $b ); |
|
84
|
1
|
50
|
|
|
|
9
|
return '' if !$b->isa( OPTIMADE::Filter::Property:: ); |
|
85
|
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
3
|
return '' if @$a != @$b; |
|
87
|
1
|
|
|
|
|
2
|
for my $i (0..$#$a) { |
|
88
|
2
|
50
|
|
|
|
4
|
return '' if defined $a->[$i] ^ defined $b->[$i]; |
|
89
|
2
|
50
|
|
|
|
4
|
next if !defined $a->[$i]; |
|
90
|
2
|
50
|
|
|
|
5
|
return '' if $a->[$i] ne $b->[$i]; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
1
|
|
|
|
|
11
|
return 1; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |