line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Plugin::Count; |
2
|
1
|
|
|
1
|
|
79923
|
use 5.014002; |
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
496
|
use namespace::autoclean; |
|
1
|
|
|
|
|
19357
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
581
|
use Mouse::Role; |
|
1
|
|
|
|
|
18952
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
439
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
256
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
requires qw/query_builder dbh/; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub count { |
12
|
2
|
|
|
2
|
0
|
882
|
my ($self, $table, $column, $where, $opt) = @_; |
13
|
2
|
|
100
|
|
|
11
|
$where //= {}; |
14
|
2
|
|
100
|
|
|
8
|
$column //= '*'; |
15
|
|
|
|
|
|
|
|
16
|
2
|
50
|
|
|
|
7
|
croak '(Aniki::Plugin::Count#count) `where` condition must be a reference.' unless ref $where; |
17
|
|
|
|
|
|
|
|
18
|
2
|
50
|
|
|
|
5
|
if (ref $column) { |
19
|
0
|
|
|
|
|
0
|
croak 'Do not pass HashRef/ArrayRef to second argument. Usage: $db->count($table[, $column[, $where[, $opt]]])'; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
7
|
my ($sql, @binds) = $self->query_builder->select($table, [\"COUNT($column)"], $where, $opt); |
23
|
2
|
|
|
|
|
776
|
my ($count) = $self->dbh->selectrow_array($sql, undef, @binds); |
24
|
2
|
|
|
|
|
270
|
return $count; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
__END__ |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=encoding utf-8 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Aniki::Plugin::Count - Count rows in database. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 SYNOPSIS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
package MyDB; |
41
|
|
|
|
|
|
|
use Mouse v2.4.5; |
42
|
|
|
|
|
|
|
extends qw/Aniki/; |
43
|
|
|
|
|
|
|
with qw/Aniki::Plugin::Count/; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package main; |
46
|
|
|
|
|
|
|
my $db = MyDB->new(...); |
47
|
|
|
|
|
|
|
$db->count('user'); # => The number of rows in 'user' table. |
48
|
|
|
|
|
|
|
$db->count('user', '*', {type => 2}); # => SELECT COUNT(*) FROM user WHERE type=2 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SEE ALSO |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
L<perl> |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 LICENSE |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Copyright (C) karupanerura. |
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
|
|
|
|
|
|
|
karupanerura E<lt>karupa@cpan.orgE<gt> |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |