line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Pageset; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
########################################################################### |
4
|
|
|
|
|
|
|
# Class::DBI::Pageset |
5
|
|
|
|
|
|
|
# Mark Grimes |
6
|
|
|
|
|
|
|
# $Id: NAMESPACE.pm,v 1.3 2006/11/29 02:40:22 mgrimes Exp $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# A flexible pager utility for Class::DBI |
9
|
|
|
|
|
|
|
# Copyright (c) 2008 Mark Grimes (mgrimes@cpan.org). |
10
|
|
|
|
|
|
|
# All rights reserved. This program is free software; you can redistribute |
11
|
|
|
|
|
|
|
# it and/or modify it under the same terms as Perl itself. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Heavily inspired by (read: stolen from) Class::DBI::Pager and |
14
|
|
|
|
|
|
|
# DBIx::Class::ResultSet::Data::Pageset. Thanks! |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
########################################################################### |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
40590
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
19
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
22
|
|
|
|
|
|
|
our $AUTOLOAD; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
1527
|
use Class::DBI 0.90; |
|
1
|
|
|
|
|
74603
|
|
|
1
|
|
|
|
|
9
|
|
25
|
|
|
|
|
|
|
our $PAGER_IMPLEMENTATION = 'Data::Pageset'; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
|
0
|
sub _croak { require Carp; Carp::croak(@_); } |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub import { |
30
|
1
|
|
|
1
|
|
8
|
my $class = shift; |
31
|
1
|
|
|
|
|
2
|
my $pkg = caller(0); |
32
|
1
|
|
|
1
|
|
87
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
481
|
|
33
|
1
|
|
|
|
|
2
|
*{"$pkg\::pager"} = \&_pager; |
|
1
|
|
|
|
|
4
|
|
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
5
|
$PAGER_IMPLEMENTATION = shift if @_; |
36
|
1
|
|
|
|
|
5
|
( my $pager_implementation_file = "$PAGER_IMPLEMENTATION.pm" ) =~ s{::}{/}g; |
37
|
1
|
|
|
|
|
1
|
eval { require $pager_implementation_file; }; |
|
1
|
|
|
|
|
842
|
|
38
|
1
|
50
|
|
|
|
5626
|
_croak "Unable to use $PAGER_IMPLEMENTATION: $@" if $@; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _pager { |
42
|
0
|
|
|
0
|
|
|
my $pkg = shift; |
43
|
0
|
|
|
|
|
|
my @args = qw( entries_per_page current_page pages_per_set mode ); |
44
|
0
|
|
|
|
|
|
my $opts = {}; |
45
|
0
|
|
0
|
|
|
|
while ( @_ and not ref $_[0] ) { |
46
|
0
|
|
|
|
|
|
$opts->{ shift @args } = shift; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
my $ref = ref $_[0] eq 'HASH' ? shift : {}; |
49
|
0
|
|
|
|
|
|
return bless { |
50
|
|
|
|
|
|
|
pkg => $pkg, |
51
|
|
|
|
|
|
|
pager => undef, |
52
|
|
|
|
|
|
|
pager_opts => { %$opts, %$ref, }, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
__PACKAGE__; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub AUTOLOAD { |
58
|
0
|
|
|
0
|
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
( my $method = $AUTOLOAD ) =~ s/.*://; |
60
|
0
|
0
|
0
|
|
|
|
if ( ref($self) && $self->{pkg}->can($method) ) { |
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $iter = $self->{pkg}->$method(@_); |
62
|
0
|
0
|
|
|
|
|
UNIVERSAL::isa( $iter, 'Class::DBI::Iterator' ) |
63
|
|
|
|
|
|
|
or _croak("$method doesn't return Class::DBI::Itertor"); |
64
|
0
|
|
|
|
|
|
my $pager_opts = $self->{pager_opts}; |
65
|
0
|
|
|
|
|
|
my $pager = $self->{pager} = $PAGER_IMPLEMENTATION->new( { |
66
|
|
|
|
|
|
|
total_entries => $iter->count, |
67
|
|
|
|
|
|
|
%$pager_opts, |
68
|
|
|
|
|
|
|
} ); |
69
|
0
|
|
|
|
|
|
return $iter->slice( $pager->first - 1, $pager->last - 1 ); |
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
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |