| 1 | package DBIx::dbMan::Extension::TotalCount; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | |||
| 6 | our $VERSION = '0.03'; | ||
| 7 | |||
| 8 | 1; | ||
| 9 | |||
| 10 | sub IDENTIFICATION { return "000001-000073-000003"; } | ||
| 11 | |||
| 12 | sub preference { return -30; } | ||
| 13 | |||
| 14 | sub known_actions { return [ qw/OUTPUT/ ]; } | ||
| 15 | |||
| 16 | sub init { | ||
| 17 | my $obj = shift; | ||
| 18 | $obj->{-mempool}->set('total_count',1); | ||
| 19 | } | ||
| 20 | |||
| 21 | sub handle_action { | ||
| 22 | my ($obj,%action) = @_; | ||
| 23 | |||
| 24 | $action{processed} = 1; | ||
| 25 | if ($action{action} eq 'OUTPUT' and $action{type} eq 'select' and $action{sql} and $obj->{-mempool}->get('total_count') and defined $action{result}) { | ||
| 26 | my $num = scalar @{$action{result}}; | ||
| 27 | my $cols = scalar @{$action{fieldnames}}; | ||
| 28 | $action{output} .= ($num==0?"No":"Total $num")." line".($num==1?"":"s")." of output in $cols column".($cols==1?"":"s").".\n"; | ||
| 29 | } | ||
| 30 | |||
| 31 | return %action; | ||
| 32 | } |