line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::HasOrderByClause; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
16310
|
use strict; |
|
27
|
|
|
|
|
56
|
|
|
27
|
|
|
|
|
1130
|
|
4
|
27
|
|
|
27
|
|
128
|
use warnings; |
|
27
|
|
|
|
|
44
|
|
|
27
|
|
|
|
|
784
|
|
5
|
27
|
|
|
27
|
|
126
|
use namespace::autoclean; |
|
27
|
|
|
|
|
45
|
|
|
27
|
|
|
|
|
192
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2504
|
use Fey::Types qw( ArrayRef OrderByElement ); |
|
27
|
|
|
|
|
52
|
|
|
27
|
|
|
|
|
198
|
|
10
|
27
|
|
|
27
|
|
289657
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
63
|
|
|
27
|
|
|
|
|
1706
|
|
11
|
|
|
|
|
|
|
|
12
|
27
|
|
|
27
|
|
133
|
use Moose::Role; |
|
27
|
|
|
|
|
36
|
|
|
27
|
|
|
|
|
276
|
|
13
|
27
|
|
|
27
|
|
122857
|
use MooseX::Params::Validate 0.21 qw( pos_validated_list ); |
|
27
|
|
|
|
|
890
|
|
|
27
|
|
|
|
|
185
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has '_order_by' => ( |
16
|
|
|
|
|
|
|
traits => ['Array'], |
17
|
|
|
|
|
|
|
is => 'bare', |
18
|
|
|
|
|
|
|
isa => ArrayRef, |
19
|
|
|
|
|
|
|
default => sub { [] }, |
20
|
|
|
|
|
|
|
handles => { |
21
|
|
|
|
|
|
|
_add_order_by_elements => 'push', |
22
|
|
|
|
|
|
|
_has_order_by_elements => 'count', |
23
|
|
|
|
|
|
|
_order_by => 'elements', |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
init_arg => undef, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub order_by { |
29
|
19
|
|
|
19
|
1
|
1349
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
19
|
100
|
|
|
|
70
|
my $count = @_ ? @_ : 1; |
32
|
19
|
|
|
|
|
99
|
my (@by) = pos_validated_list( |
33
|
|
|
|
|
|
|
\@_, |
34
|
|
|
|
|
|
|
( ( { isa => OrderByElement } ) x $count ), |
35
|
|
|
|
|
|
|
MX_PARAMS_VALIDATE_NO_CACHE => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
1166
|
$self->_add_order_by_elements(@by); |
39
|
|
|
|
|
|
|
|
40
|
18
|
|
|
|
|
52
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub order_by_clause { |
44
|
123
|
|
|
123
|
1
|
184
|
my $self = shift; |
45
|
123
|
|
|
|
|
130
|
my $dbh = shift; |
46
|
|
|
|
|
|
|
|
47
|
123
|
100
|
|
|
|
4373
|
return unless $self->_has_order_by_elements(); |
48
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
34
|
my $sql = 'ORDER BY '; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
|
|
|
617
|
my @elt = $self->_order_by(); |
52
|
|
|
|
|
|
|
|
53
|
18
|
|
|
|
|
44
|
for my $elt (@elt) { |
54
|
27
|
100
|
|
|
|
667
|
if ( !blessed $elt ) { |
55
|
7
|
|
|
|
|
23
|
$sql .= q{ } . uc $elt; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
20
|
100
|
|
|
|
65
|
$sql .= ', ' if $elt != $elt[0]; |
59
|
20
|
|
|
|
|
77
|
$sql .= $elt->sql_or_alias($dbh); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
18
|
|
|
|
|
810
|
return $sql; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# ABSTRACT: A role for queries which can include a ORDER BY clause |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=pod |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Fey::Role::SQL::HasOrderByClause - A role for queries which can include a ORDER BY clause |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 VERSION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
version 0.43 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SYNOPSIS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Moose 2.1200; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
with 'Fey::Role::SQL::HasOrderByClause'; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 DESCRIPTION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Classes which do this role represent a query which can include a |
91
|
|
|
|
|
|
|
C<ORDER BY> clause. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 METHODS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This role provides the following methods: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 $query->order_by() |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
See the L<Fey::SQL section on ORDER BY Clauses|Fey::SQL/ORDER BY |
100
|
|
|
|
|
|
|
Clauses> for more details. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 $query->order_by_clause() |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns the C<ORDER BY> clause portion of the SQL statement as a |
105
|
|
|
|
|
|
|
string. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 BUGS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
See L<Fey> for details on how to report bugs. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This software is Copyright (c) 2011 - 2015 by Dave Rolsky. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This is free software, licensed under: |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |