line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPTIMADE::Filter::Property; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
901
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
200
|
|
4
|
7
|
|
|
7
|
|
33
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
203
|
|
5
|
|
|
|
|
|
|
|
6
|
7
|
|
|
7
|
|
509
|
use parent 'OPTIMADE::Filter::Modifiable'; |
|
7
|
|
|
|
|
312
|
|
|
7
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
452
|
use Scalar::Util qw(blessed); |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
1183
|
|
9
|
|
|
|
|
|
|
|
10
|
2330
|
|
|
2330
|
|
4863
|
use overload '@{}' => sub { return $_[0]->{name} }, |
11
|
473
|
|
|
473
|
|
56629
|
'""' => sub { return $_[0]->to_filter }, |
12
|
0
|
|
|
0
|
|
0
|
'==' => sub { return $_[0]->_eq( $_[1] ) }, |
13
|
7
|
|
|
7
|
|
7361
|
'eq' => sub { return $_[0]->_eq( $_[1] ) }; |
|
7
|
|
|
1
|
|
5920
|
|
|
7
|
|
|
|
|
126
|
|
|
1
|
|
|
|
|
219
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $identifier_re = q/([a-z_][a-z0-9_]*)/; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
223
|
|
|
223
|
0
|
512
|
my $class = shift; |
19
|
223
|
|
|
|
|
948
|
return bless { name => \@_ }, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub to_filter |
23
|
|
|
|
|
|
|
{ |
24
|
687
|
|
|
687
|
0
|
1165
|
my( $self ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Validate |
27
|
687
|
|
|
|
|
1501
|
$self->validate; |
28
|
687
|
|
|
|
|
1165
|
for my $name (@$self) { |
29
|
696
|
|
|
|
|
1253
|
my $lc_name = lc $name; |
30
|
696
|
100
|
|
|
|
3827
|
next if $lc_name =~ /^$identifier_re$/; |
31
|
1
|
|
|
|
|
12
|
die "name '$lc_name' does not match identifier syntax: $identifier_re"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
686
|
|
|
|
|
1388
|
return join '.', map { lc } @$self; |
|
693
|
|
|
|
|
3190
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub to_SQL |
38
|
|
|
|
|
|
|
{ |
39
|
84
|
|
|
84
|
0
|
155
|
my( $self, $options ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
84
|
100
|
|
|
|
168
|
$options = {} unless $options; |
42
|
|
|
|
|
|
|
my( $delim, $placeholder ) = ( |
43
|
|
|
|
|
|
|
$options->{delim}, |
44
|
|
|
|
|
|
|
$options->{placeholder}, |
45
|
84
|
|
|
|
|
146
|
); |
46
|
84
|
50
|
|
|
|
146
|
$delim = "'" unless $delim; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Validate |
49
|
84
|
|
|
|
|
209
|
$self->validate; |
50
|
84
|
50
|
|
|
|
139
|
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
|
84
|
|
|
|
|
137
|
my $sql = join '.', map { "${delim}$_${delim}" } @$self; |
|
86
|
|
|
|
|
270
|
|
57
|
|
|
|
|
|
|
|
58
|
84
|
100
|
|
|
|
187
|
if( wantarray ) { |
59
|
83
|
|
|
|
|
245
|
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
|
|
|
|
|
17
|
return $code->( $self, @_ ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub validate |
74
|
|
|
|
|
|
|
{ |
75
|
771
|
|
|
771
|
0
|
1088
|
my $self = shift; |
76
|
771
|
50
|
|
|
|
1459
|
die 'name undefined for OPTIMADE::Filter::Property' if !@$self; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _eq |
80
|
|
|
|
|
|
|
{ |
81
|
1
|
|
|
1
|
|
5
|
my( $a, $b ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
7
|
return '' if !blessed( $b ); |
84
|
1
|
50
|
|
|
|
11
|
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
|
|
|
|
5
|
return '' if defined $a->[$i] ^ defined $b->[$i]; |
89
|
2
|
50
|
|
|
|
4
|
next if !defined $a->[$i]; |
90
|
2
|
50
|
|
|
|
4
|
return '' if $a->[$i] ne $b->[$i]; |
91
|
|
|
|
|
|
|
} |
92
|
1
|
|
|
|
|
14
|
return 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |