add dbic internals warning and todo note about bind values
[dbsrgits/DBIx-Class-RowCountStatistics.git] / lib / CtrlO / DBIC / Cursor / RowCountStatistics.pm
CommitLineData
231ba12b 1use strict;
2use warnings;
3
4package CtrlO::DBIC::Cursor::RowCountStatistics;
5use Class::Method::Modifiers;
6
f6e5b275 7use CtrlO::DBIC::Cursor::RowCountStatistics::Storage;
8
231ba12b 9use parent 'DBIx::Class::Storage::DBI::Cursor';
10
11our $VERSION = '0.000001'; # 0.0.1
12$VERSION = eval $VERSION;
13
f6e5b275 14around new => sub {
15 my $orig = shift;
16 my ($class, $storage, @rest) = @_;
17 return $orig->(
18 $class,
19 CtrlO::DBIC::Cursor::RowCountStatistics::Storage->new($storage),
20 @rest,
21 );
22};
23
231ba12b 24after next => sub {
25 my ($self) = @_;
26 $self->{_ctrlo_rcs_count}++
27 unless $self->{_done};
28};
29
f6e5b275 30around all => sub {
31 my $orig = shift;
32 my ($self) = @_;
33 my @rows = $orig->(@_);
34 $self->_emit_query_complete(scalar(@rows));
35 return @rows;
36};
37
231ba12b 38before __finish_sth => sub {
39 my ($self) = @_;
40 my $sql = $self->sth->{Statement};
f6e5b275 41 $self->_emit_query_complete($self->{_ctrlo_rcs_count} || 0);
42};
43
44sub _emit_query_complete {
45 my ($self, $count) = @_;
231ba12b 46 $self->storage->debugobj->query_complete(
f6e5b275 47 $count,
48 $self->storage->_cached_sql,
231ba12b 49 # TODO pass bind params
dcf77f95 50 ) if $self->storage->debug
51 and $self->storage->debugobj->can('query_complete');
f6e5b275 52}
231ba12b 53
541;
55
56=head1 NAME
57
af26217a 58CtrlO::DBIC::Cursor::RowCountStatistics - Provide row-count statistics
231ba12b 59
60=head1 SYNOPSIS
61
af26217a 62 my $schema = Schema->connect(
63 $dsn, $username, $password,
64 {},
65 { cursor_class => 'CtrlO::DBIC::Cursor::RowCountStatistics' },
66 );
67
231ba12b 68=head1 DESCRIPTION
69
af26217a 70This L<DBIx::Class::Storage::DBI::Cursor> subclass allows you to log the
71number of rows that were fetched through the cursor.
72
cf23f5e2 73B<Warning>: This module currently lies on L<DBIx::Class> internals and
74might break with an update.
75
af26217a 76=head1 DEBUG OBJECT METHODS
77
78=head2 query_complete (optional)
79
80If available on the L<DBIx::Class::Storage/debugobj>, this method will be
81called with the following signature:
82
83 sub query_complete {
84 my ($self, $row_count, $sql, @bind_values) = @_;
85 ...
86 }
87
cf23f5e2 88B<Note>: The passing of the C<@bind_values> is currently not yet
89implemented, and no values will be passed yet.
90
231ba12b 91=head1 AUTHOR
92
93 r.sedlacek@shadowcat.co.uk
94
95=head1 CONTRIBUTORS
96
af26217a 97None yet.
231ba12b 98
99=head1 COPYRIGHT
100
101Copyright (c) 2015 the CtrlO::DBIC::Cursor::RowCountStatistics L</AUTHOR> and L</CONTRIBUTORS>
102as listed above.
103
af26217a 104=cut