line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
3
|
|
|
3
|
|
312750
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
116
|
|
3
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
253
|
|
4
|
|
|
|
|
|
|
package Net::LDAP::Filter::SQL; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
3
|
|
|
3
|
|
99
|
$Net::LDAP::Filter::SQL::AUTHORITY = 'cpan:ESSELENS'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
$Net::LDAP::Filter::SQL::VERSION = '0.03'; |
10
|
|
|
|
|
|
|
} |
11
|
3
|
|
|
3
|
|
2551
|
use parent qw/Net::LDAP::Filter/; |
|
3
|
|
|
|
|
1037
|
|
|
3
|
|
|
|
|
17
|
|
12
|
3
|
|
|
3
|
|
14550
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
2759
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _filter_parse { |
15
|
20
|
|
|
20
|
|
34
|
my $self = shift; |
16
|
20
|
|
66
|
|
|
97
|
my $hash = shift || $self; |
17
|
20
|
|
|
|
|
25
|
my $args = shift; |
18
|
|
|
|
|
|
|
|
19
|
20
|
|
100
|
|
|
83
|
$self->{sql_values} ||= []; |
20
|
20
|
|
100
|
|
|
169
|
$self->{sql_ops} ||= { reverse qw/& and |
21
|
|
|
|
|
|
|
| or |
22
|
|
|
|
|
|
|
! not |
23
|
|
|
|
|
|
|
= equalityMatch |
24
|
|
|
|
|
|
|
~ approxMatch |
25
|
|
|
|
|
|
|
>= greaterOrEqual |
26
|
|
|
|
|
|
|
<= lessOrEqual |
27
|
|
|
|
|
|
|
/ }; |
28
|
|
|
|
|
|
|
|
29
|
20
|
|
|
|
|
90
|
foreach (keys %$hash) { |
30
|
36
|
100
|
|
|
|
111
|
/^and/ and return '('. join(') and (', map { $self->_filter_parse($_) } @{$hash->{$_}}) .')'; |
|
8
|
|
|
|
|
29
|
|
|
4
|
|
|
|
|
15
|
|
31
|
32
|
100
|
|
|
|
80
|
/^or/ and return '('. join(') or (', map { $self->_filter_parse($_) } @{$hash->{$_}}) .')'; |
|
2
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
4
|
|
32
|
31
|
50
|
|
|
|
71
|
/^not/ and return 'not (' . $self->_filter_parse($hash->{$_}) . ')'; |
33
|
31
|
100
|
|
|
|
82
|
/^present/ and return $hash->{$_}.' is not null'; |
34
|
30
|
100
|
|
|
|
104
|
/^(equalityMatch|greaterOrEqual|lessOrEqual|approxMatch)/ and do { |
35
|
11
|
|
|
|
|
21
|
push @{$self->{sql_values}}, $hash->{$_}->{assertionValue}; |
|
11
|
|
|
|
|
45
|
|
36
|
11
|
|
|
|
|
42
|
return $self->_escape_identifier($hash->{$_}->{attributeDesc}) . " ". $self->{sql_ops}->{$1} . " ?"; |
37
|
|
|
|
|
|
|
}; |
38
|
19
|
100
|
|
|
|
274
|
/^substrings/ and do { |
39
|
3
|
|
|
|
|
9
|
my $str = join("%", "", map { values %$_ } @{$hash->{$_}->{substrings}}); |
|
3
|
|
|
|
|
21
|
|
|
3
|
|
|
|
|
14
|
|
40
|
3
|
100
|
|
|
|
19
|
$str =~ s/^.// if exists $hash->{$_}->{substrings}[0]{initial}; |
41
|
3
|
100
|
|
|
|
15
|
$str .= '%' unless exists $hash->{$_}->{substrings}[-1]{final}; |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
5
|
push @{$self->{sql_values}}, $str; |
|
3
|
|
|
|
|
9
|
|
44
|
3
|
|
|
|
|
17
|
return '(' . $self->_escape_identifier($hash->{$_}->{type}) .' like ?) '; |
45
|
|
|
|
|
|
|
}; |
46
|
16
|
50
|
|
|
|
40
|
/^extensibleMatch/ and do { |
47
|
0
|
|
|
|
|
0
|
push @{$self->{sql_values}}, $hash->{$_}->{matchValue}; |
|
0
|
|
|
|
|
0
|
|
48
|
0
|
|
|
|
|
0
|
return $self->_escape_identifier($hash->{$_}->{matchingRule}) . '(' . $self->_escape_identifier($hash->{$_}->{type}) . ') = ?'; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _escape_identifier { |
55
|
14
|
|
|
14
|
|
29
|
my ($self,$ident) = @_; |
56
|
14
|
50
|
|
|
|
57
|
$ident =~ s/\W//g and warn "identifier '$ident' contains non word characters"; |
57
|
14
|
|
|
|
|
207
|
return $ident; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub sql_clause { |
61
|
10
|
|
|
10
|
1
|
47502
|
my $self = shift; |
62
|
10
|
|
33
|
|
|
100
|
$self->{sql_clause} ||= $self->_filter_parse(); |
63
|
10
|
|
|
|
|
65
|
return $self->{sql_clause}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub sql_values { |
67
|
10
|
|
|
10
|
1
|
9025
|
my $self = shift; |
68
|
10
|
50
|
|
|
|
36
|
$self->_filter_parse() unless $self->{sql_values}; |
69
|
10
|
|
|
|
|
68
|
return $self->{sql_values}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub as_string { |
73
|
1
|
|
|
1
|
1
|
745
|
my $self = shift; |
74
|
1
|
|
|
|
|
4
|
return Net::LDAP::Filter::_string(map { $_ => $self->{$_} } grep {! /^sql_/} keys %$self); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
4
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub new_from_data { |
78
|
1
|
|
|
1
|
1
|
451
|
my $self = shift; |
79
|
1
|
|
|
|
|
3
|
my $dataref = shift; |
80
|
1
|
50
|
|
|
|
6
|
croak "expecting a HASH" unless ref $dataref eq 'HASH'; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
5
|
my %data = %$dataref; |
83
|
1
|
|
|
|
|
5
|
return bless(\%data, 'Net::LDAP::Filter::SQL'); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
42; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |