line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::HasOrderByClause; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
15316
|
use strict; |
|
27
|
|
|
|
|
53
|
|
|
27
|
|
|
|
|
1044
|
|
4
|
27
|
|
|
27
|
|
135
|
use warnings; |
|
27
|
|
|
|
|
43
|
|
|
27
|
|
|
|
|
793
|
|
5
|
27
|
|
|
27
|
|
158
|
use namespace::autoclean; |
|
27
|
|
|
|
|
41
|
|
|
27
|
|
|
|
|
194
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.42'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2204
|
use Fey::Types qw( ArrayRef OrderByElement ); |
|
27
|
|
|
|
|
51
|
|
|
27
|
|
|
|
|
192
|
|
10
|
27
|
|
|
27
|
|
284974
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
66
|
|
|
27
|
|
|
|
|
1681
|
|
11
|
|
|
|
|
|
|
|
12
|
27
|
|
|
27
|
|
124
|
use Moose::Role; |
|
27
|
|
|
|
|
40
|
|
|
27
|
|
|
|
|
236
|
|
13
|
27
|
|
|
27
|
|
115655
|
use MooseX::Params::Validate 0.08 qw( pos_validated_list ); |
|
27
|
|
|
|
|
760
|
|
|
27
|
|
|
|
|
179
|
|
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
|
1470
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
19
|
100
|
|
|
|
61
|
my $count = @_ ? @_ : 1; |
32
|
19
|
|
|
|
|
81
|
my (@by) = pos_validated_list( |
33
|
|
|
|
|
|
|
\@_, |
34
|
|
|
|
|
|
|
( ( { isa => OrderByElement } ) x $count ), |
35
|
|
|
|
|
|
|
MX_PARAMS_VALIDATE_NO_CACHE => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
1137
|
$self->_add_order_by_elements(@by); |
39
|
|
|
|
|
|
|
|
40
|
18
|
|
|
|
|
54
|
return $self; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub order_by_clause { |
44
|
123
|
|
|
123
|
1
|
177
|
my $self = shift; |
45
|
123
|
|
|
|
|
162
|
my $dbh = shift; |
46
|
|
|
|
|
|
|
|
47
|
123
|
100
|
|
|
|
4305
|
return unless $self->_has_order_by_elements(); |
48
|
|
|
|
|
|
|
|
49
|
18
|
|
|
|
|
38
|
my $sql = 'ORDER BY '; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
|
|
|
647
|
my @elt = $self->_order_by(); |
52
|
|
|
|
|
|
|
|
53
|
18
|
|
|
|
|
36
|
for my $elt (@elt) { |
54
|
27
|
100
|
|
|
|
516
|
if ( !blessed $elt ) { |
55
|
7
|
|
|
|
|
17
|
$sql .= q{ } . uc $elt; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
20
|
100
|
|
|
|
72
|
$sql .= ', ' if $elt != $elt[0]; |
59
|
20
|
|
|
|
|
75
|
$sql .= $elt->sql_or_alias($dbh); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
18
|
|
|
|
|
730
|
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.42 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SYNOPSIS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
use Moose 0.90; |
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 |