line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Role::SQL::HasLimitClause; |
2
|
|
|
|
|
|
|
|
3
|
27
|
|
|
27
|
|
14148
|
use strict; |
|
27
|
|
|
|
|
52
|
|
|
27
|
|
|
|
|
984
|
|
4
|
27
|
|
|
27
|
|
127
|
use warnings; |
|
27
|
|
|
|
|
38
|
|
|
27
|
|
|
|
|
752
|
|
5
|
27
|
|
|
27
|
|
123
|
use namespace::autoclean; |
|
27
|
|
|
|
|
42
|
|
|
27
|
|
|
|
|
181
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.42'; |
8
|
|
|
|
|
|
|
|
9
|
27
|
|
|
27
|
|
2201
|
use Scalar::Util qw( blessed ); |
|
27
|
|
|
|
|
48
|
|
|
27
|
|
|
|
|
1632
|
|
10
|
|
|
|
|
|
|
|
11
|
27
|
|
|
27
|
|
130
|
use Fey::Types qw( PosInteger PosOrZeroInteger Undef ); |
|
27
|
|
|
|
|
64
|
|
|
27
|
|
|
|
|
202
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
277904
|
use Moose::Role; |
|
27
|
|
|
|
|
68
|
|
|
27
|
|
|
|
|
251
|
|
14
|
27
|
|
|
27
|
|
120369
|
use MooseX::Params::Validate 0.08 qw( pos_validated_list ); |
|
27
|
|
|
|
|
800
|
|
|
27
|
|
|
|
|
180
|
|
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
|
43
|
my $self = shift; |
30
|
8
|
|
|
|
|
36
|
my ( $limit, $offset ) = pos_validated_list( |
31
|
|
|
|
|
|
|
\@_, |
32
|
|
|
|
|
|
|
{ isa => ( PosInteger | Undef ) }, |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
isa => PosOrZeroInteger, |
35
|
|
|
|
|
|
|
optional => 1, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
|
|
|
352
|
$self->_set_limit($limit) |
40
|
|
|
|
|
|
|
if defined $limit; |
41
|
7
|
100
|
|
|
|
85
|
$self->_set_offset($offset) |
42
|
|
|
|
|
|
|
if defined $offset; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
24
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub limit_clause { |
48
|
115
|
|
|
115
|
1
|
127
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
115
|
100
|
100
|
|
|
3162
|
return unless $self->_has_limit() || $self->_has_offset(); |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
15
|
my $sql = ''; |
53
|
|
|
|
|
|
|
|
54
|
7
|
100
|
|
|
|
190
|
$sql .= 'LIMIT ' . $self->_limit() |
55
|
|
|
|
|
|
|
if $self->_has_limit(); |
56
|
7
|
100
|
100
|
|
|
181
|
$sql .= q{ } |
57
|
|
|
|
|
|
|
if $self->_has_limit() && $self->_has_offset(); |
58
|
7
|
100
|
|
|
|
178
|
$sql .= 'OFFSET ' . $self->_offset() |
59
|
|
|
|
|
|
|
if $self->_has_offset(); |
60
|
|
|
|
|
|
|
|
61
|
7
|
|
|
|
|
46
|
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.42 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Moose 0.90; |
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 |