File Coverage

blib/lib/Class/ReluctantORM/Monitor/QueryCount.pm
Criterion Covered Total %
statement 9 14 64.2
branch n/a
condition n/a
subroutine 3 7 42.8
pod 4 4 100.0
total 16 25 64.0


line stmt bran cond sub pod time code
1             package Class::ReluctantORM::Monitor::QueryCount;
2              
3             =head1 NAME
4              
5             Class::ReluctantORM::Monitor::QueryCount - Ongoing count of queries
6              
7             =head1 SYNOPSIS
8              
9             use aliased 'Class::ReluctantORM::Monitor::QueryCount';
10             my $mon = QueryCount->new();
11             Class::ReluctantORM->install_global_monitor($mon);
12             Pirate->install_class_monitor($mon);
13              
14             # Do a query.... logging and highwater scorekeeping happens
15             Pirate->fetch(...);
16              
17             # Read from the monitor - should increase by 1 or more with each DB operation
18             my $count = $mon->last_measured_value();
19              
20             # Reset counter to 0
21             $mon->reset();
22              
23              
24             =head1 DESCRIPTION
25              
26             Simply counts the number of times the database is queried. This value may not increase (due to caching by a Registry or Static, a query may not be needed to perform a fetch). Also, some drivers may have to perform two queries to perform an operation (Eg, insert-and-return-values).
27              
28             This is a Measuring Monitor. Note that highwater tracking is supported, but rather meaningless.
29              
30             =cut
31              
32 1     1   5 use strict;
  1         1  
  1         28  
33 1     1   6 use warnings;
  1         2  
  1         25  
34 1     1   12 use base 'Class::ReluctantORM::Monitor::Measuring';
  1         2  
  1         165  
35              
36 0     0 1   sub permitted_events { return qw(execute_begin); }
37 0     0 1   sub default_events { return qw(execute_begin); }
38 0     0 1   sub measurement_label { return 'Number of Queries'; }
39             sub take_measurement {
40 0     0 1   my ($mon, %event) = @_;
41 0           return $mon->last_measured_value + 1;
42             }
43              
44              
45             1;