line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::DBI::Plugin::AggregateFunction; |
2
|
1
|
|
|
1
|
|
28541
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
43
|
|
3
|
1
|
|
|
1
|
|
5
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
4
|
|
|
|
|
|
|
$VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1378
|
use SQL::Abstract; |
|
1
|
|
|
|
|
12823
|
|
|
1
|
|
|
|
|
74
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub import { |
9
|
0
|
|
|
0
|
|
|
my $class = shift; |
10
|
0
|
|
|
|
|
|
my $pkg = caller(0); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
16
|
no strict 'refs';
|
|
1
|
|
|
|
|
122
|
|
|
1
|
|
|
|
|
155
|
|
13
|
0
|
|
|
|
|
|
*{"$pkg\::mk_aggregate_function"} = \&mk_aggregate_function; |
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub mk_aggregate_function { |
17
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
18
|
0
|
|
|
|
|
|
my ($aggregate_func, $alias) = @_; |
19
|
0
|
|
0
|
|
|
|
$alias ||= $aggregate_func; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$class->set_sql( "AggregateFunction_$aggregate_func" => <<__SQL__ );
|
22
|
|
|
|
|
|
|
SELECT $aggregate_func( %s )
|
23
|
|
|
|
|
|
|
FROM __TABLE__
|
24
|
|
|
|
|
|
|
WHERE %s
|
25
|
|
|
|
|
|
|
__SQL__
|
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
7
|
no strict 'refs';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
305
|
|
28
|
0
|
|
|
|
|
|
*{"$class\::$alias"} = sub {
|
29
|
0
|
|
|
0
|
|
|
my $proto = shift;
|
30
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto;
|
31
|
0
|
|
|
|
|
|
my $aggregate_column = shift;
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
my $where = (ref $_[0]) ? $_[0] : { @_ };
|
34
|
0
|
0
|
|
|
|
|
my $attr = (ref $_[0]) ? $_[1] : undef;
|
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $sql = SQL::Abstract->new(%$attr);
|
37
|
0
|
|
|
|
|
|
my($phrase, @bind) = $sql->where($where);
|
38
|
0
|
|
|
|
|
|
$phrase =~ s/^\s*WHERE\s*//i;
|
39
|
0
|
0
|
|
|
|
|
$phrase = ' 1 = 1 ' unless $phrase; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $sql_method = "sql_AggregateFunction_$aggregate_func";
|
42
|
0
|
|
|
|
|
|
my $sth = $class->$sql_method( $aggregate_column, $phrase );
|
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return $sth->select_val( @bind );
|
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
__END__ |