More changelogging
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Role / QueryCounter.pm
CommitLineData
62fa8aec 1package DBIx::Class::Storage::DBI::Role::QueryCounter;
2
3use Moose::Role;
4requires '_query_start';
5
6=head1 NAME
7
92bc2a19 8DBIx::Class::Storage::DBI::Role::QueryCounter - Role to add a query counter
62fa8aec 9
10=head1 SYNOPSIS
11
12 my $query_count = $schema->storage->query_count;
13
14=head1 DESCRIPTION
15
16Each time the schema does a query, increment the counter.
17
18=head1 ATTRIBUTES
19
20This package defines the following attributes.
21
48580715 22=head2 _query_count
62fa8aec 23
24Is the attribute holding the current query count. It defines a public reader
25called 'query_count' which you can use to access the total number of queries
26that DBIC has run since connection.
27
28=cut
29
30has '_query_count' => (
31 reader=>'query_count',
32 writer=>'_set_query_count',
33 isa=>'Int',
34 required=>1,
35 default=>0,
36);
37
38
39=head1 METHODS
40
41This module defines the following methods.
42
43=head2 _query_start
44
48580715 45Override on the method so that we count the queries.
62fa8aec 46
47=cut
48
49around '_query_start' => sub {
50 my ($_query_start, $self, @args) = @_;
51 $self->_increment_query_count;
52 return $self->$_query_start(@args);
53};
54
55
56=head2 _increment_query_count
57
58Used internally. You won't need this unless you enjoy messing with the query
59count.
60
61=cut
62
63sub _increment_query_count {
64 my $self = shift @_;
65 my $current = $self->query_count;
66 $self->_set_query_count(++$current);
67}
68
69
70=head1 AUTHORS
71
72See L<DBIx::Class> for more information regarding authors.
73
74=head1 LICENSE
75
76You may distribute this code under the same terms as Perl itself.
77
78=cut
79
80
92bc2a19 811;