line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::HasLimitClause; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
15859
|
use strict; |
|
27
|
|
|
|
|
53
|
|
|
27
|
|
|
|
|
1111
|
|
4
|
27
|
|
|
27
|
|
145
|
use warnings; |
|
27
|
|
|
|
|
46
|
|
|
27
|
|
|
|
|
845
|
|
5
|
27
|
|
|
27
|
|
170
|
use namespace::autoclean; |
|
27
|
|
|
|
|
46
|
|
|
27
|
|
|
|
|
193
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.43'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2492
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
49
|
|
|
27
|
|
|
|
|
1678
|
|
10
|
|
|
|
|
|
|
|
11
|
27
|
|
|
27
|
|
138
|
use Fey::Types qw( PosInteger PosOrZeroInteger Undef ); |
|
27
|
|
|
|
|
44
|
|
|
27
|
|
|
|
|
203
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
305438
|
use Moose::Role; |
|
27
|
|
|
|
|
70
|
|
|
27
|
|
|
|
|
279
|
|
14
|
27
|
|
|
27
|
|
130053
|
use MooseX::Params::Validate 0.21 qw( pos_validated_list ); |
|
27
|
|
|
|
|
880
|
|
|
27
|
|
|
|
|
183
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has '_limit' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
writer => '_set_limit', |
19
|
|
|
|
|
|
|
predicate => '_has_limit', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has '_offset' => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
writer => '_set_offset', |
25
|
|
|
|
|
|
|
predicate => '_has_offset', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub limit { |
29
|
8
|
|
|
8
|
1
|
59
|
my $self = shift; |
30
|
8
|
|
|
|
|
49
|
my ( $limit, $offset ) = pos_validated_list( |
31
|
|
|
|
|
|
|
\@_, |
32
|
|
|
|
|
|
|
{ isa => ( PosInteger | Undef ) }, |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
isa => PosOrZeroInteger, |
35
|
|
|
|
|
|
|
optional => 1, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
|
|
|
382
|
$self->_set_limit($limit) |
40
|
|
|
|
|
|
|
if defined $limit; |
41
|
7
|
100
|
|
|
|
85
|
$self->_set_offset($offset) |
42
|
|
|
|
|
|
|
if defined $offset; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
21
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub limit_clause { |
48
|
115
|
|
|
115
|
1
|
148
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
115
|
100
|
100
|
|
|
3345
|
return unless $self->_has_limit() || $self->_has_offset(); |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
14
|
my $sql = ''; |
53
|
|
|
|
|
|
|
|
54
|
7
|
100
|
|
|
|
210
|
$sql .= 'LIMIT ' . $self->_limit() |
55
|
|
|
|
|
|
|
if $self->_has_limit(); |
56
|
7
|
100
|
100
|
|
|
191
|
$sql .= q{ } |
57
|
|
|
|
|
|
|
if $self->_has_limit() && $self->_has_offset(); |
58
|
7
|
100
|
|
|
|
203
|
$sql .= 'OFFSET ' . $self->_offset() |
59
|
|
|
|
|
|
|
if $self->_has_offset(); |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
59
|
return $sql; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# ABSTRACT: A role for queries which can include a LIMIT clause |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=pod |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Fey::Role::SQL::HasLimitClause - A role for queries which can include a LIMIT clause |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 VERSION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
version 0.43 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Moose 2.1200; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
with 'Fey::Role::SQL::HasLimitClause'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 DESCRIPTION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Classes which do this role represent a query which can include a |
89
|
|
|
|
|
|
|
C<LIMIT> clause. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 METHODS |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This role provides the following methods: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 $query->limit() |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
See the L<Fey::SQL section on LIMIT Clauses|Fey::SQL/LIMIT Clauses> |
98
|
|
|
|
|
|
|
for more details. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 $query->limit_clause() |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the C<LIMIT> clause portion of the SQL statement as a string. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 BUGS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
See L<Fey> for details on how to report bugs. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This software is Copyright (c) 2011 - 2015 by Dave Rolsky. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This is free software, licensed under: |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |