line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package SQL::QueryBuilder::Pretty; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
27508
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
68
|
|
10
|
1
|
|
|
1
|
|
1031
|
use Data::Dumper; |
|
1
|
|
|
|
|
9235
|
|
|
1
|
|
|
|
|
84
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Module::Pluggable |
13
|
1
|
|
|
|
|
8
|
'search_path' => [ |
14
|
|
|
|
|
|
|
'SQL::QueryBuilder::Pretty::Database::ANSI', |
15
|
|
|
|
|
|
|
], |
16
|
|
|
|
|
|
|
'instantiate' => 'new', |
17
|
|
|
|
|
|
|
'sub_name' => 'rules' |
18
|
1
|
|
|
1
|
|
794
|
; |
|
1
|
|
|
|
|
9873
|
|
19
|
1
|
|
|
1
|
|
600
|
use SQL::QueryBuilder::Pretty::Print; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
327
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
23
|
0
|
|
|
|
|
|
my %self = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if ( my $database = delete $self{'-database'} ) { |
|
|
0
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$class = CORE::join( q{::}, $class, 'Database', $database ); |
27
|
0
|
0
|
|
|
|
|
eval "use $class; 1" or croak $@; |
28
|
0
|
|
|
|
|
|
return $class->new( %self ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( my $handler = delete $self{'-handler'} ) { |
31
|
0
|
|
|
|
|
|
$class = CORE::join( q{::}, $class, 'Handler', ref $handler ); |
32
|
0
|
0
|
|
|
|
|
eval "use $class; 1" or croak $@; |
33
|
0
|
|
|
|
|
|
return $class->new( %self, 'handler' => $handler ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
0
|
|
|
|
return bless { %self }, ref $class || $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub print { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
my $query = shift; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Initializes the print object |
45
|
0
|
|
|
|
|
|
my $print = SQL::QueryBuilder::Pretty::Print->new( %{ $self } ); |
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Get rules in the correct order |
48
|
|
|
|
|
|
|
# TODO: load unique rules by name |
49
|
0
|
|
|
|
|
|
my @rules = sort { $a->order <=> $b->order } $self->rules(); |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
while ( $query ) { |
52
|
0
|
|
|
|
|
|
for my $rule ( @rules ) { |
53
|
0
|
|
|
|
|
|
my $match = $rule->match; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if ( $query =~ s/^($match)//smx ) { |
56
|
|
|
|
|
|
|
# A rule can exit in error, in that case continue trying |
57
|
0
|
0
|
|
|
|
|
last if $rule->action($print, $1); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $print->query; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
__END__ |