Commit | Line | Data |
4c248161 |
1 | package DBIx::Class::Storage::Statistics; |
2 | use strict; |
3 | |
4 | use base qw/DBIx::Class::AccessorGroup Class::Data::Accessor/; |
5 | __PACKAGE__->mk_group_accessors(simple => qw/callback debugfh/); |
6 | |
7 | =head1 NAME |
8 | |
9 | DBIx::Class::Storage::Statistics - SQL Statistics |
10 | |
11 | =head1 SYNOPSIS |
12 | |
13 | =head1 DESCRIPTION |
14 | |
15 | This class is called by DBIx::Class::Storage::DBI as a means of collecting |
16 | statistics on it's actions. Using this class alone merely prints the SQL |
17 | executed, the fact that it completes and begin/end notification for |
18 | transactions. |
19 | |
20 | To really use this class you should subclass it and create your own method |
21 | for collecting the statistics as discussed in L<DBIx::Class::Manual::Cookbook>. |
22 | |
23 | =head1 METHODS |
24 | |
25 | =cut |
26 | |
27 | =head2 new |
28 | |
29 | Returns a new L<DBIx::Class::Storage::Statistics> object. |
30 | |
31 | =cut |
32 | sub new { |
33 | my $self = bless({}, ref($_[0]) || $_[0]); |
34 | |
35 | return $self; |
36 | } |
37 | |
38 | =head2 debugfh |
39 | |
40 | Sets or retrieves the filehandle used for trace/debug output. This should |
41 | be an IO::Handle compatible object (only the C<print> method is used). Initially |
42 | should be set to STDERR - although see information on the |
43 | L<DBIX_CLASS_STORAGE_DBI_DEBUG> environment variable. |
44 | |
45 | =head2 txn_begin |
46 | |
47 | Called when a transaction begins. |
48 | |
49 | =cut |
50 | sub txn_begin { |
51 | my $self = shift(); |
52 | } |
53 | |
54 | =head2 txn_rollback |
55 | |
56 | Called when a transaction is rolled back. |
57 | |
58 | =cut |
59 | sub txn_rollback { |
60 | my $self = shift(); |
61 | } |
62 | |
63 | =head2 txn_commit |
64 | |
65 | Called when a transaction is committed. |
66 | |
67 | =cut |
68 | sub txn_commit { |
69 | my $self = shift(); |
70 | } |
71 | |
72 | =head2 query_start |
73 | |
74 | Called before a query is executed. The first argument is the SQL string being |
75 | executed and subsequent arguments are the parameters used for the query. |
76 | |
77 | =cut |
78 | sub query_start { |
79 | my $self = shift(); |
80 | my $string = shift(); |
81 | |
82 | if(defined($self->callback())) { |
83 | $string =~ m/^(\w+)/; |
84 | $self->callback()->($1, $string); |
85 | return; |
86 | } |
87 | |
88 | $self->debugfh->print("$string: " . join(', ', @_) . "\n"); |
89 | } |
90 | |
91 | =head2 query_end |
92 | |
93 | Called when a query finishes executing. Has the same arguments as query_start. |
94 | |
95 | =cut |
96 | sub query_end { |
97 | my $self = shift(); |
98 | my $string = shift(); |
99 | } |
100 | |
101 | 1; |
102 | |
103 | =head1 AUTHORS |
104 | |
105 | Cory G. Watson <gphat@cpan.org> |
106 | |
107 | =head1 LICENSE |
108 | |
109 | You may distribute this code under the same license as Perl itself. |
110 | |
111 | =cut |