blib/lib/DBIx/Pager.pm

filter: Statementstmt 31.5% 18 / 57 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 38.4% 5 / 13 Podpod 100% 7 / 7 totaltotal 32.2% 30 / 93 CC 8 SCAR 20.3
CC
8
Cov
25%
new
20.0
_load_page_info
12.0
has_next
6.0
CRAP 7.7
↑ Summary
1 package DBIx::Pager;
2 # $Id: Pager.pm,v 1.2 2002/08/06 02:06:14 ikechin Exp $
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 __PACKAGE__->mk_accessors(qw(total limit offset));
10  
11 2 $VERSION = '0.02';
12  
13 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
14 0 my $class = shift;
15 0 my %args = @_;
16 my $self = bless {
17 dsn => $args{dsn},
18 user => $args{user},
19 password => $args{password},
20 dbh => $args{dbh},
21 table => $args{table},
22 offset => $args{offset} || 0,
23 limit => $args{limit},
24 where_clause => $args{where_clause},
25 0 ▶ }, $class;
Condition0%0/2
$args{'offset'} || 0
l!l
00
MC/DC0%0/1
$args{'offset'} || 0
$args{'offset'}
Truth table0%0/2
A
A= $args{'offset'}
Aresult
11
00
26 0 ▶ if ($self->{dsn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dsn"}) 0 0 0
27 0 eval " require DBI; ";
28 $self->{dbh} = DBI->connect(
29 $self->{dsn}, $self->{user}, $self->{password},
30 {
31 0 ▶ RaiseError => 1,
Branch: 1 branch
BranchTrueFalseTotal
$self->{"dbh"} = "DBI"->connect($self->{"dsn"}, $self->{"user"}, $self->{"password"}, {"RaiseError", 1, "PrintError", 1}) or die $DBI::errstr 0 0 0
32 PrintError => 1
33 }
34 ) or die $DBI::errstr;
35 }
36 0 $self->_load_page_info;
37 0 $self;
38 }
39  
40 0 ▶sub _load_page_info {
Subroutine _load_page_info: not called CC=3 SCAR=24.8
41 0 my $self = shift;
42 0 my $dbh = $self->{dbh};
43 0 my $table = $self->{table};
44 0 my $sth;
45 0 ▶ if (ref $self->{where_clause} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'where_clause'} eq 'ARRAY') { } 0 0 0
46 0 my @args = @{$self->{where_clause}};
47 0 my $where = shift @args;
48 0 $sth = $dbh->prepare("SELECT COUNT(*) FROM $table $where");
49 0 $sth->execute(@args)
50 }
51 else {
52 0 ▶ my $where = $self->{where_clause} || "";
Condition0%0/2
$self->{'where_clause'} || ''
l!l
00
MC/DC0%0/1
$self->{'where_clause'} || ''
$self->{'where_clause'}
Truth table0%0/2
A
A= $self->{'where_clause'}
Aresult
11
00
53 0 $sth = $dbh->prepare("SELECT COUNT(*) FROM $table $where");
54 0 $sth->execute;
55 }
56 0 my $count = $sth->fetchrow_arrayref->[0];
57 0 $sth->finish;
58 0 $dbh->disconnect;
59 0 $self->{total} = $count;
60 }
61  
62 0 ▶sub has_next {
Subroutine has_next: not called CC=2 SCAR=17.9
Pod documented
63 0 my $self = shift;
64 0 ▶ if ($self->{total} > $self->{offset} + $self->{limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"total"} > $self->{"offset"} + $self->{"limit"}) 0 0 0
65 0 return 1;
66 }
67 0 return 0;
68 }
69  
70 0 ▶sub has_prev {
Subroutine has_prev: not called CC=2 SCAR=17.9
Pod documented
71 0 my $self = shift;
72 0 ▶ return $self->{offset} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'offset'} ? : 0 0 0
73 }
74  
75 0 ▶sub next_offset {
Subroutine next_offset: not called CC=1 SCAR=6.9
Pod documented
76 0 my $self = shift;
77 0 return $self->{offset} + $self->{limit};
78 }
79  
80 0 ▶sub prev_offset {
Subroutine prev_offset: not called CC=1 SCAR=6.9
Pod documented
81 0 my $self = shift;
82 0 my $prev = $self->{offset} - $self->{limit};
83 }
84  
85 0 ▶sub page_count {
Subroutine page_count: not called CC=1 SCAR=6.9
Pod documented
86 0 my $self = shift;
87 0 return POSIX::ceil($self->{total} / $self->{limit});
88 }
89  
90 0 ▶sub current_page {
Subroutine current_page: not called CC=1 SCAR=6.9
Pod documented
91 0 my $self = shift;
92 0 return int($self->{offset} / $self->{limit}) + 1;
93 }
94  
95 2 1;
96 __END__
↑ Summary