4 package DBIx::Class::RowCountStatistics;
5 use Class::Method::Modifiers;
7 use DBIx::Class::RowCountStatistics::Storage;
9 use parent 'DBIx::Class::Storage::DBI::Cursor';
11 our $VERSION = '0.000001'; # 0.0.1
12 $VERSION = eval $VERSION;
14 # Wrap the original ::Storage::DBI we received so we can extract data
15 # from it's usage by the Cursor.
18 my ($class, $storage, @rest) = @_;
22 DBIx::Class::RowCountStatistics::Storage->new($storage),
29 $self->{_ctrlo_rcs_count}++
30 unless $self->{_done};
37 my @rows = $orig->(@_);
39 # ->all does its own finalization, so we fire the complete event
41 $self->_emit_query_complete(scalar(@rows));
45 before __finish_sth => sub {
48 $self->_emit_query_complete($self->{_ctrlo_rcs_count} || 0);
51 sub _emit_query_complete {
52 my ($self, $count) = @_;
54 $self->storage->debugobj->query_complete(
56 $self->storage->_cached_sql,
57 # TODO pass bind params
58 ) if $self->storage->debug
59 and $self->storage->debugobj->can('query_complete');
66 DBIx::Class::RowCountStatistics - Provide row-count statistics
70 my $schema = Schema->connect(
71 $dsn, $username, $password,
73 { cursor_class => 'DBIx::Class::RowCountStatistics' },
78 This module overrides internal L<DBIx::Class> functionality, and might
79 break with every update.
83 This L<DBIx::Class::Storage::DBI::Cursor> subclass allows you to log the
84 number of rows that were fetched through the cursor.
86 B<Warning>: This module currently lies on L<DBIx::Class> internals and
87 might break with an update.
89 =head1 DEBUG OBJECT METHODS
91 =head2 query_complete (optional)
93 If available on the L<DBIx::Class::Storage/debugobj>, this method will be
94 called with the following signature:
97 my ($self, $row_count, $sql) = @_;
103 Development of this module was sponsored by
107 =item * Ctrl O L<http://ctrlo.com>
113 Robert Sedlacek <r.sedlacek@shadowcat.co.uk>
117 Matt S. Trout <mst@shadowcat.co.uk>
121 Copyright (c) 2015 the DBIx::Class::RowCountStatistics L</AUTHOR> and L</CONTRIBUTORS>