line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package SQL::QueryBuilder::Pretty::Print; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
10
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
516
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
14
|
0
|
|
|
|
|
|
my %self = ( |
15
|
|
|
|
|
|
|
'-indent_ammount' => 4, |
16
|
|
|
|
|
|
|
'-indent_char' => ' ', |
17
|
|
|
|
|
|
|
'-new_line' => "\n", |
18
|
|
|
|
|
|
|
@_, |
19
|
|
|
|
|
|
|
'indent_level' => 0, |
20
|
|
|
|
|
|
|
'indent_multiplier' => 1, |
21
|
|
|
|
|
|
|
'skip_next_space' => 0, |
22
|
|
|
|
|
|
|
'query' => undef, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
0
|
|
|
|
return bless { %self }, ref $class || $class; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _generic_method { |
29
|
0
|
|
|
0
|
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
my $key = shift; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
$self->{ $key } = shift if defined $_[0]; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self->{ $key }; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub current_indent { |
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return |
41
|
0
|
|
|
|
|
|
$self->indent_char x ( $self->indent_level * $self->indent_ammount ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub indent { |
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
46
|
0
|
|
0
|
|
|
|
my $multiplier = shift || 1; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->indent_level(+1 * $multiplier); |
49
|
0
|
|
|
|
|
|
$self->var( $self->current_indent ); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
1
|
|
sub indent_ammount { return shift->{'-indent_ammount'}; } |
55
|
0
|
|
|
0
|
1
|
|
sub indent_char { return shift->{'-indent_char'}; } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub indent_level { |
58
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$self->{'indent_level'} += shift if defined $_[0]; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
return $self->{'indent_level'} >= 0 ? $self->{'indent_level'} : 0; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
1
|
|
sub indent_multiplier { return shift->_generic_method( 'indent_multiplier', @_ ); } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new_line { |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
$self->var( $self->{'-new_line'} ); |
70
|
0
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
|
sub query { return shift->{'query'}; } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub unindent { |
76
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
77
|
0
|
|
0
|
|
|
|
my $multiplier = shift || 1; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$self->indent_level(-1 * $multiplier); |
80
|
0
|
|
|
|
|
|
$self->var( $self->current_indent ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return 1; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub var { |
86
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
$self->{'query'} .= shift; |
88
|
0
|
|
|
|
|
|
return 1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub skip_next_space { |
92
|
0
|
|
|
0
|
1
|
|
return shift->_generic_method( 'skip_next_space' , @_ ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |