line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Column::Alias; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
120
|
use strict; |
|
26
|
|
|
|
|
33
|
|
|
26
|
|
|
|
|
931
|
|
4
|
26
|
|
|
26
|
|
123
|
use warnings; |
|
26
|
|
|
|
|
40
|
|
|
26
|
|
|
|
|
756
|
|
5
|
26
|
|
|
26
|
|
346
|
use namespace::autoclean; |
|
26
|
|
|
|
|
39
|
|
|
26
|
|
|
|
|
116
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
8
|
|
|
|
|
|
|
|
9
|
26
|
|
|
26
|
|
10960
|
use Fey::Exceptions qw( object_state_error ); |
|
26
|
|
|
|
|
80
|
|
|
26
|
|
|
|
|
1789
|
|
10
|
26
|
|
|
26
|
|
12123
|
use Fey::Table; |
|
26
|
|
|
|
|
105
|
|
|
26
|
|
|
|
|
1376
|
|
11
|
26
|
|
|
26
|
|
706
|
use Fey::Table::Alias; |
|
26
|
|
|
|
|
45
|
|
|
26
|
|
|
|
|
708
|
|
12
|
26
|
|
|
26
|
|
141
|
use Fey::Types qw( Column Str ); |
|
26
|
|
|
|
|
49
|
|
|
26
|
|
|
|
|
242
|
|
13
|
|
|
|
|
|
|
|
14
|
26
|
|
|
26
|
|
319708
|
use Moose 2.1200; |
|
26
|
|
|
|
|
938
|
|
|
26
|
|
|
|
|
234
|
|
15
|
26
|
|
|
26
|
|
159669
|
use MooseX::SemiAffordanceAccessor 0.03; |
|
26
|
|
|
|
|
775
|
|
|
26
|
|
|
|
|
200
|
|
16
|
26
|
|
|
26
|
|
83490
|
use MooseX::StrictConstructor 0.13; |
|
26
|
|
|
|
|
682
|
|
|
26
|
|
|
|
|
202
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
with 'Fey::Role::ColumnLike'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'id' => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
lazy_build => 1, |
23
|
|
|
|
|
|
|
init_arg => undef, |
24
|
|
|
|
|
|
|
clearer => '_clear_id', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has 'column' => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => Column, |
30
|
|
|
|
|
|
|
handles => [ |
31
|
|
|
|
|
|
|
qw( name type generic_type length precision |
32
|
|
|
|
|
|
|
is_auto_increment is_nullable table ) |
33
|
|
|
|
|
|
|
], |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has 'alias_name' => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => Str, |
39
|
|
|
|
|
|
|
lazy_build => 1, |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
with 'Fey::Role::Named'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
my %Numbers; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _build_alias_name { |
48
|
2
|
|
|
2
|
|
5
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
6
|
my $name = $self->name(); |
51
|
2
|
|
100
|
|
|
11
|
$Numbers{$name} ||= 0; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
43
|
return $name . ++$Numbers{$name}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
1
|
841
|
sub is_alias {1} |
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
5
|
1
|
152
|
sub sql { $_[1]->quote_identifier( $_[0]->alias_name() ) } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub sql_with_alias { |
62
|
1
|
|
|
1
|
1
|
5
|
my $sql = $_[1]->quote_identifier( |
63
|
|
|
|
|
|
|
undef, |
64
|
|
|
|
|
|
|
$_[0]->_containing_table_name_or_alias(), |
65
|
|
|
|
|
|
|
$_[0]->name(), |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
44
|
$sql .= ' AS '; |
69
|
1
|
|
|
|
|
29
|
$sql .= $_[1]->quote_identifier( $_[0]->alias_name() ); |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
41
|
return $sql; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
4
|
|
|
4
|
1
|
20
|
sub sql_or_alias { goto &sql } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _build_id { |
77
|
2
|
|
|
2
|
|
6
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
9
|
my $table = $self->table(); |
80
|
|
|
|
|
|
|
|
81
|
2
|
100
|
|
|
|
11
|
object_state_error |
82
|
|
|
|
|
|
|
'The id attribute cannot be determined for a column object which has no table.' |
83
|
|
|
|
|
|
|
unless $table; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
45
|
return $table->id() . '.' . $self->alias_name(); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# This is here to avoid a circular use issue. |
91
|
|
|
|
|
|
|
require Fey::Column; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# ABSTRACT: Represents an alias for a column |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 NAME |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Fey::Column::Alias - Represents an alias for a column |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 VERSION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
version 0.43 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 SYNOPSIS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $alias = $user_id_col->alias(); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This class represents an alias for a column. Column aliases allow you |
116
|
|
|
|
|
|
|
to use the same column in different ways multiple times in a query, |
117
|
|
|
|
|
|
|
which makes certain types of queries simpler to express. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 METHODS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 Fey::Column::Alias->new() |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This method constructs a new C<Fey::Column::Alias> object. It takes |
124
|
|
|
|
|
|
|
the following parameters: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=over 4 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * column - required |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is the C<Fey::Column> object which we are aliasing. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * alias_name - optional |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This should be a valid column name for your DBMS. If not provided, a |
135
|
|
|
|
|
|
|
unique name is automatically created. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=back |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 $alias->name() |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This returns the name of the column for which this object is an alias. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 $alias->alias_name() |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Returns the name for this alias. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 $alias->type() |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 $alias->generic_type() |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 $alias->length() |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 $alias->precision() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 $alias->is_auto_increment() |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 $alias->is_nullable() |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 $alias->default() |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Returns the specified attribute for the column, just like the |
162
|
|
|
|
|
|
|
C<Fey::Column> methods of the same name. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 $alias->table() |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Returns the C<Fey::Table> object to which the column alias belongs, if |
167
|
|
|
|
|
|
|
any. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 $alias->is_alias() |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Always returns false. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 $alias->sql() |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 $alias->sql_with_alias() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 $alias->sql_or_alias() |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns the appropriate SQL snippet for the alias. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 $alias->id() |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Returns a unique identifier for the column. This method throws an |
184
|
|
|
|
|
|
|
exception if the alias does not belong to a table. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 ROLES |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This class does the L<Fey::Role::ColumnLike> and L<Fey::Role::Named> |
189
|
|
|
|
|
|
|
roles. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 BUGS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
See L<Fey> for details on how to report bugs. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This software is Copyright (c) 2011 - 2015 by Dave Rolsky. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This is free software, licensed under: |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |