blib/lib/Otogiri/Plugin/Count.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 2 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 97.3% 37 / 38 SCAR 11.0
CC
3
Cov
100%
count
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
↑ Summary Build »
1 package Otogiri::Plugin::Count;
2 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = "0.01";
7  
8 2 ▶use Otogiri;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Otogiri::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our @EXPORT = qw(count);
12  
13 sub count {
14 3 ▶ my ($self, $table, $column, $where, $opt) = @_;
Subroutine count: called CC=3 SCAR=11.0
Pod undocumented
15  
16 3 ▶ if ( ref $column eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $column eq "HASH") 1 2 3
17 1 $opt = $where;
18 1 $where = $column;
19 1 $column = '*';
20 }
21  
22 3 ▶ $column ||= '*';
Condition100%2/2
$column ||= "*"
l!l
21
MC/DC100%1/1
$column ||= "*"
$column
Truth table100%2/2
A
A= $column
Aresult
11
00
23  
24 3 my ($sql, @binds) = $self->maker->select($table, [\"COUNT($column)"], $where, $opt);
25  
26 3 my ($cnt) = $self->dbh->selectrow_array($sql, {}, @binds);
27 3 return $cnt;
28 }
29  
30 2 1;
31 __END__
32  
33 =encoding utf-8
34  
35 =head1 NAME
36  
37 Otogiri::Plugin::Count - Otogiri plugin to count rows in database.
38  
39 =head1 SYNOPSIS
40  
41 use Otogiri;
42 use Otogiri::Plugin;
43 my $db = Otogiri->new( connect_info => [ ... ] );
44 $db->load_plugin('Count');
45 my $count = $db->count('some_table'); # SELECT COUNT(*) FROM some_table
46  
47 my $count2 = $db->count('some_table', 'column1', { group_id => 123 }); # SELECT COUNT(column1) WHERE group_id=123
48 my $count3 = $db->count('some_table', { group_id => 123 }); # SELECT COUNT(*) WHERE group_id=123
49  
50 =head1 DESCRIPTION
51  
52 Otogiri::Plugin::Count is plugin for L<Otogiri> to count database rows.
53  
54 =head1 LICENSE
55  
56 Copyright (C) Takuya Tsuchida.
57  
58 This library is free software; you can redistribute it and/or modify
59 it under the same terms as Perl itself.
60  
61 =head1 AUTHOR
62  
63 Takuya Tsuchida E<lt>tsucchi@cpan.orgE<gt>
64  
65 =cut
66  
↑ Summary Build »