line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBomb::Query::Limit; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
DBomb::Query::Limit - A LIMIT clause. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
12
|
|
|
12
|
|
65
|
use strict; |
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
561
|
|
12
|
12
|
|
|
12
|
|
63
|
use warnings; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
545
|
|
13
|
|
|
|
|
|
|
our $VERSION = '$Revision: 1.3 $'; |
14
|
|
|
|
|
|
|
|
15
|
12
|
|
|
12
|
|
60
|
use Carp::Assert; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
100
|
|
16
|
|
|
|
|
|
|
use Class::MethodMaker |
17
|
12
|
|
|
|
|
126
|
'new_with_init' => 'new', |
18
|
|
|
|
|
|
|
'get_set' => [qw(offset max_rows)], |
19
|
12
|
|
|
12
|
|
2014
|
; |
|
12
|
|
|
|
|
29
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
## new Limit () |
22
|
|
|
|
|
|
|
## new Limit ($max_rows) |
23
|
|
|
|
|
|
|
## new Limit ($offset,$max_rows) |
24
|
|
|
|
|
|
|
## new Limit (+{ offset =>, max_rows=>1}) |
25
|
|
|
|
|
|
|
sub init { |
26
|
3
|
|
|
3
|
0
|
33
|
my $self = shift; |
27
|
3
|
|
|
|
|
92
|
$self->offset(0); |
28
|
3
|
|
|
|
|
124
|
$self->max_rows(undef); |
29
|
3
|
50
|
|
|
|
31
|
return $self unless @_; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
66
|
|
|
49
|
assert( (@_ == 1 && (ref($_[0])? ref($_[0]) eq 'HASH' : 1)) |
32
|
|
|
|
|
|
|
|| (@_ == 2 && !ref($_[0]) && ! ref($_[1])), 'parameter validation'); |
33
|
|
|
|
|
|
|
|
34
|
3
|
50
|
|
|
|
45
|
if (ref($_[0]) eq 'HASH'){ |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
$self->offset($_[0]->{'offset'}); |
36
|
0
|
|
|
|
|
0
|
$self->max_rows($_[0]->{'max_rows'}); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif (@_==1){ |
39
|
2
|
|
|
|
|
99
|
$self->max_rows(shift); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif(@_ == 2){ |
42
|
1
|
|
|
|
|
36
|
$self->offset(shift); |
43
|
1
|
|
|
|
|
40
|
$self->max_rows(shift); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub sql { |
48
|
0
|
|
|
0
|
0
|
|
my ($self, $dbh) = @_; |
49
|
0
|
|
|
|
|
|
my($o,$m) = ($self->offset,$self->max_rows); |
50
|
0
|
0
|
0
|
|
|
|
return '' unless defined($o) && defined($m); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
assert(defined($m), 'valid max_rows'); |
53
|
0
|
0
|
|
|
|
|
assert($o >= 0, 'valid offset') if defined $o; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $sql = " LIMIT "; |
56
|
0
|
0
|
|
|
|
|
if(defined $o){ |
57
|
0
|
|
|
|
|
|
$sql .= " $o, "; |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$sql .= "$m"; |
60
|
0
|
|
|
|
|
|
return $sql; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |