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