line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::MoCo::Pageset; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
31087
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
283
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
our $AUTOLOAD; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $PAGER_IMPLEMENTATION = 'Data::Pageset'; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
0
|
|
0
|
sub _croak { require Carp; Carp::croak(@_); } |
|
0
|
|
|
|
|
0
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
1
|
|
|
1
|
|
8
|
my $class = shift; |
15
|
1
|
|
|
|
|
3
|
my $pkg = caller(0); |
16
|
2
|
|
|
2
|
|
12
|
no strict 'refs'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
1302
|
|
17
|
1
|
|
|
|
|
1
|
*{"$pkg\::pager"} = \&_pager; |
|
1
|
|
|
|
|
5
|
|
18
|
1
|
50
|
|
|
|
6
|
$PAGER_IMPLEMENTATION = shift if @_; |
19
|
1
|
|
|
|
|
4
|
( my $pager_implementation_file = "$PAGER_IMPLEMENTATION.pm" ) =~ s{::}{/}g; |
20
|
1
|
|
|
|
|
2
|
eval { require $pager_implementation_file; }; |
|
1
|
|
|
|
|
772
|
|
21
|
1
|
50
|
|
|
|
9644
|
_croak "Unable to use $PAGER_IMPLEMENTATION: $@" if $@; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _pager { |
25
|
0
|
|
|
0
|
|
|
my $pkg = shift; |
26
|
0
|
|
|
|
|
|
my @args = qw( entries_per_page current_page pages_per_set mode ); |
27
|
0
|
|
|
|
|
|
my $opts = {}; |
28
|
0
|
|
0
|
|
|
|
while ( @_ and not ref $_[0] ) { |
29
|
0
|
|
|
|
|
|
$opts->{ shift @args } = shift; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
0
|
|
|
|
|
my $ref = ref $_[0] eq 'HASH' ? shift : {}; |
32
|
0
|
|
|
|
|
|
return bless { |
33
|
|
|
|
|
|
|
pkg => $pkg, |
34
|
|
|
|
|
|
|
pager => undef, |
35
|
|
|
|
|
|
|
pager_opts => { %$opts, %$ref, }, |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
__PACKAGE__; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub AUTOLOAD { |
41
|
0
|
|
|
0
|
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
( my $method = $AUTOLOAD ) =~ s/.*://; |
43
|
0
|
0
|
0
|
|
|
|
if ( ref($self) && $self->{pkg}->can($method) ) { |
|
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $where = ''; |
45
|
0
|
0
|
|
|
|
|
if ($_[1]) { |
|
|
0
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my %args = @_; |
47
|
0
|
|
|
|
|
|
$where = \%args; |
48
|
|
|
|
|
|
|
} elsif ($_[0]) { |
49
|
0
|
|
|
|
|
|
$where = shift; |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
my $pager_opts = $self->{pager_opts}; |
52
|
0
|
0
|
|
|
|
|
my $offset = $pager_opts->{current_page} |
53
|
|
|
|
|
|
|
? ( $pager_opts->{current_page} -1 ) * $pager_opts->{entries_per_page} : 0; |
54
|
0
|
0
|
|
|
|
|
my $limit = $pager_opts->{entries_per_page} |
55
|
|
|
|
|
|
|
? $pager_opts->{entries_per_page} : 1; |
56
|
0
|
0
|
|
|
|
|
$self->{pager} = $PAGER_IMPLEMENTATION->new( { |
57
|
|
|
|
|
|
|
'total_entries' => $self->{pkg}->count( ref $where eq 'HASH' ? $where->{where} : ''), |
58
|
|
|
|
|
|
|
%$pager_opts, |
59
|
|
|
|
|
|
|
} ); |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if ( ref $where eq 'HASH' ) { |
62
|
0
|
0
|
|
|
|
|
if ( $offset ) { |
63
|
0
|
|
|
|
|
|
$where->{offset} = $offset; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
$where->{limit} = $limit; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
return ($where) ? $self->{pkg}->$method(%$where) : $self->{pkg}->$method->slice($offset, $offset + $limit -1); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} elsif ( $PAGER_IMPLEMENTATION->can($method) ) { |
71
|
0
|
0
|
|
|
|
|
$self->{pager} or _croak("Can't call pager methods before searching"); |
72
|
0
|
|
|
|
|
|
return $self->{pager}->$method(@_); |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
0
|
|
|
|
_croak( |
75
|
|
|
|
|
|
|
qq(Can't locate object method "$method" via package ) . ref($self) |
76
|
|
|
|
|
|
|
|| $self ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
|
|
sub DESTROY { } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |