X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCtrlO%2FDBIC%2FCursor%2FRowCountStatistics.pm;h=882cc54b846c5cc4e817ef6ea3a242cc4d36803f;hb=f6e5b2758375964fd8eba24b30de87e91c6782bf;hp=ba0a828c1516f695e6065a48df3d734552e81695;hpb=cda17ef7d18ccb27ae534ec03c3333efe6bec534;p=dbsrgits%2FDBIx-Class-RowCountStatistics.git diff --git a/lib/CtrlO/DBIC/Cursor/RowCountStatistics.pm b/lib/CtrlO/DBIC/Cursor/RowCountStatistics.pm index ba0a828..882cc54 100644 --- a/lib/CtrlO/DBIC/Cursor/RowCountStatistics.pm +++ b/lib/CtrlO/DBIC/Cursor/RowCountStatistics.pm @@ -4,26 +4,51 @@ use warnings; package CtrlO::DBIC::Cursor::RowCountStatistics; use Class::Method::Modifiers; +use CtrlO::DBIC::Cursor::RowCountStatistics::Storage; + use parent 'DBIx::Class::Storage::DBI::Cursor'; our $VERSION = '0.000001'; # 0.0.1 $VERSION = eval $VERSION; +around new => sub { + my $orig = shift; + my ($class, $storage, @rest) = @_; + return $orig->( + $class, + CtrlO::DBIC::Cursor::RowCountStatistics::Storage->new($storage), + @rest, + ); +}; + after next => sub { my ($self) = @_; $self->{_ctrlo_rcs_count}++ unless $self->{_done}; }; +around all => sub { + my $orig = shift; + my ($self) = @_; + my @rows = $orig->(@_); + $self->_emit_query_complete(scalar(@rows)); + return @rows; +}; + before __finish_sth => sub { my ($self) = @_; my $sql = $self->sth->{Statement}; + $self->_emit_query_complete($self->{_ctrlo_rcs_count} || 0); +}; + +sub _emit_query_complete { + my ($self, $count) = @_; $self->storage->debugobj->query_complete( - $self->{_ctrlo_rcs_count} || 0, - $sql, + $count, + $self->storage->_cached_sql, # TODO pass bind params ) if $self->storage->debug; -}; +} 1;