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