File Coverage

blib/lib/Class/DBI/Plugin/QueriesTime.pm
Criterion Covered Total %
statement 23 38 60.5
branch 0 8 0.0
condition n/a
subroutine 7 8 87.5
pod n/a
total 30 54 55.5


line stmt bran cond sub pod time code
1             package Class::DBI::Plugin::QueriesTime;
2              
3 1     1   22240 use strict;
  1         2  
  1         49  
4 1     1   5 use warnings;
  1         1  
  1         36  
5 1     1   2792 use Time::HiRes qw( tv_interval gettimeofday );
  1         1896  
  1         4  
6 1     1   178 use vars qw($VERSION);
  1         2  
  1         77  
7             $VERSION = '0.01';
8              
9             sub import {
10 1     1   11 my $class = shift;
11 1         2 my $pkg = caller(0);
12 1         2 my $befor_query;
13              
14 1     1   4 no strict 'refs';
  1         1  
  1         25  
15 1     1   6 no warnings 'redefine';
  1         1  
  1         325  
16 1         14 *{"$pkg\::sth_to_objects"} = sub {
17 0     0     my ($class, $sth, $args) = @_;
18 0 0         $class->_croak("sth_to_objects needs a statement handle") unless $sth;
19 0 0         unless (UNIVERSAL::isa($sth => "DBI::st")) {
20 0           my $meth = "sql_$sth";
21 0           $sth = $class->$meth();
22             }
23 0           my (%data, @rows);
24 0           eval {
25 0           $befor_query = [gettimeofday];
26 0 0         $sth->execute(@$args) unless $sth->{Active};
27 0           $sth->bind_columns(\(@data{ @{ $sth->{NAME_lc} } }));
  0            
28 0           warn "Query Time: ",tv_interval ( $befor_query );
29 0           push @rows, {%data} while $sth->fetch;
30             };
31 0 0         return $class->_croak("$class can't $sth->{Statement}: $@", err => $@)
32             if $@;
33 0           return $class->_ids_to_objects(\@rows);
34 1         3 };
35             }
36             1;
37              
38             =head1 NAME
39              
40             Class::DBI::Plugin::QueriesTime - Get your query's time.
41              
42             =head1 VERSION
43              
44             This documentation refers to Class::DBI::Plugin::QueriesTime version 0.01
45              
46             =head1 SYNOPSIS
47              
48             package YourDB;
49             use base qw/Class::DBI/;
50             use Class::DBI::Plugin::QueriesTime;
51              
52             =head1 DESCRIPTION
53              
54             Class::DBI::Plugin::QueriesTime is Extension to Class::DBI.
55             Class::DBI::Plugin::QueriesTime get your query's time.
56             Class::DBI::Plugin::QueriesTime is redefine Class::DBI::sth_to_objects.
57              
58             =head1 DEPENDENCIES
59              
60             L
61              
62             L
63              
64             =head1 BUGS AND LIMITATIONS
65              
66             There are no known bugs in this module.
67             Please report problems to Atsushi Kobayashi (Enekokak@cpan.orgE)
68             Patches are welcome.
69              
70             =head1 SEE ALSO
71              
72             L
73              
74             L
75              
76             =head1 AUTHOR
77              
78             Atsushi Kobayashi, Enekokak@cpan.orgE
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             Copyright (C) 2006 by Atsushi Kobayashi (Enekokak@cpan.orgE). All rights reserved.
83              
84             This library is free software; you can redistribute it and/or modify it
85             under the same terms as Perl itself. See L.
86              
87             =cut