line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::ReluctantORM::SQL::Expression; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Class::ReluctantORM::SQL::Expression - Base class for SQL expressions |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Abstract base class for SQL expressions. Often used as arguments to Functions, as sources for OutputColumns, and in other places. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Useful known subclasses: |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=over |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::Column |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::Param |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::Expression::Criterion |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::Expression::Literal |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::Expression::FunctionCall |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item Class::ReluctantORM::SQL::SubQuery |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=back |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
32
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
91
|
|
35
|
1
|
|
|
1
|
|
5
|
use Class::ReluctantORM::Exception; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
36
|
|
|
|
|
|
|
our $DEBUG ||= 0; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
5
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
4
|
use base 'Class::Accessor::Fast'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
387
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 VIRTUAL METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
All of these methods are intended to be overridden in subclasses. Some methods |
46
|
|
|
|
|
|
|
provide a default implementation. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 $bool = $arg->is_leaf_expression(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Indicates if the object is a terminal point on the Expression tree. Default implementation returns true. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
1
|
|
sub is_leaf_expression { return 1; } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 @args = $arg->child_expressions(); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns any children of the expression. Results only defined if is_leaf is false. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
1
|
|
sub child_expressions { Class::ReluctantORM::Exception::Call::PureVirtual->croak(); } |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 $arg = $arg->parent_expression(); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns the parent node of the expression. If undefined, this is the root node. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub parent_expression { |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
0
|
0
|
|
|
|
|
if (@_) { |
75
|
0
|
|
|
|
|
|
my $real = shift; |
76
|
0
|
|
|
|
|
|
my $weak_ref = \$real; |
77
|
0
|
|
|
|
|
|
weaken($weak_ref); |
78
|
0
|
|
|
|
|
|
$self->set('parent_ref', $weak_ref); |
79
|
|
|
|
|
|
|
} |
80
|
0
|
|
|
|
|
|
my $ref = $self->get('parent_ref'); |
81
|
0
|
0
|
|
|
|
|
if ($ref) { |
82
|
0
|
|
|
|
|
|
return ${$ref}; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
|
return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 $str = $arg->pretty_print(); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns a human-readable string representation of the expression. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
sub pretty_print { Class::ReluctantORM::Exception::Call::PureVirtual->croak(); } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 $rel->walk_leaf_expressions($coderef); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Recurses throughout the expression tree, and executes the coderef on each leaf of the expression. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The coderef will be passed the leaf expression as the only parameter. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub walk_leaf_expressions { |
105
|
0
|
|
|
0
|
1
|
|
my $expr = shift; |
106
|
0
|
|
|
|
|
|
my $coderef = shift; |
107
|
0
|
0
|
|
|
|
|
if ($expr->is_leaf_expression()) { |
108
|
0
|
|
|
|
|
|
$coderef->($expr); |
109
|
|
|
|
|
|
|
} else { |
110
|
0
|
|
|
|
|
|
foreach my $child ($expr->child_expressions()) { |
111
|
0
|
|
|
|
|
|
$child->walk_leaf_expressions($coderef); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=begin devdocs |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 $bool = $exp->is_equivalent($other); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns true if the $other expression is equivalent to this one. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Buggy - returns false negatives. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
0
|
1
|
|
sub is_equivalent { Class::ReluctantORM::Exception::Call::PureVirtual->croak(); } |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub __break_links { |
129
|
0
|
|
|
0
|
|
|
my $expr = shift; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# We maintain links both ways - parent to child and child to parent. Break them. |
132
|
0
|
|
|
|
|
|
foreach my $cexpr (grep { defined($_) } $expr->child_expressions) { |
|
0
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$cexpr->__break_links(); |
134
|
|
|
|
|
|
|
} |
135
|
0
|
|
|
|
|
|
$expr->set('parent_ref', undef); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Clinton Wolfe January 2009 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |