File Coverage

blib/lib/Class/ReluctantORM/Monitor/QuerySize.pm
Criterion Covered Total %
statement 12 24 50.0
branch n/a
condition n/a
subroutine 4 10 40.0
pod 6 6 100.0
total 22 40 55.0


line stmt bran cond sub pod time code
1             package Class::ReluctantORM::Monitor::QuerySize;
2              
3             =head1 NAME
4              
5             Class::ReluctantORM::Monitor::QuerySize - Running total of data size
6              
7             =head1 SYNOPSIS
8              
9             use aliased 'Class::ReluctantORM::Monitor::QuerySize';
10             my $mon = QuerySize->new(highwater_count => N, fatal_threshold => X);
11             Class::ReluctantORM->install_global_monitor($mon);
12             Pirate->install_class_monitor($mon);
13              
14             # Do a query....
15             Pirate->fetch(...);
16              
17             # Read from the monitor
18             my $bytes = $mon->last_measured_value();
19              
20             # Reset counter to 0 if desired - the counter gets reset at
21             # the beginning of every query anyway, but you might have need
22             # to reset it in a fetchrow callback
23             $mon->reset();
24              
25              
26             =head1 DESCRIPTION
27              
28             Keeps a running total of the number of bytes returned in all rows of the query.
29              
30             This is a Measuring Monitor.
31              
32             =cut
33              
34 1     1   5 use strict;
  1         2  
  1         28  
35 1     1   7 use warnings;
  1         1  
  1         24  
36 1     1   5 use base 'Class::ReluctantORM::Monitor::Measuring';
  1         1  
  1         72  
37              
38 1     1   6 use Class::ReluctantORM::Utilities qw(row_size);
  1         2  
  1         255  
39              
40 0     0 1   sub permitted_events { return qw(finish); }
41 0     0 1   sub default_events { return qw(finish); }
42 0     0 1   sub measurement_label { return 'Bytes Returned by Query'; }
43             sub take_measurement {
44 0     0 1   my ($mon, %event) = @_;
45             # Nothing to do - actual measurement was taken during fetchrow
46 0           return $mon->last_measured_value();
47             }
48              
49             sub notify_execute_begin {
50 0     0 1   my $self = shift;
51 0           $self->reset();
52             }
53              
54             sub notify_fetch_row {
55 0     0 1   my $self = shift;
56 0           my %args = @_;
57 0           my $sql = $args{sql_obj};
58 0           my $row = $args{row};
59 0           $self->last_measured_value($self->last_measured_value() + row_size($row));
60             }
61              
62             1;