reverse r4290 since we -do- -not- currently want these namespaces indexed
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Schema / QueryInterval.pm
CommitLineData
25e4a0c4 1package DBIx::Class::Schema::QueryInterval;
2
3use Moose;
4
5=head1 NAME
6
7DBIx::Class::Schema::Role::QueryInterval; Defines a job control interval.
8
9=head1 SYNOPSIS
10
11The following example shows how to define a job control interval and assign it
12to a particular L<DBIx::Class::Schema::Job> for a L<DBIx::Class::Schema>
13
14 my $job = DBIx::Class::Schema->new(runs => sub { print 'did job'});
15 my $interval = DBIx::Class::Schema::Interval->new(every => 10);
16
17 if($interval->matches($query_count)) {
18 print "I indentified the query count as matching";
19 }
20
21 ## $schema->isa(DBIx::Class::Schema);
22 $schema->create_and_add_at_query_intervals($interval => $job);
23
24=head1 DESCRIPTION
25
26A Query Interval defines a reoccuring period based on the query count from a
27given offset. For example, you can define a query interval of 10 queries
28with an offset of 1 query. This interval identifies query number 11, 21, 31,
29and so on.
30
31=head1 ATTRIBUTES
32
33This package defines the following attributes.
34
35=head2 every (Int)
36
37This is the 'size' of the gap identifying a query as matching a particular
38interval. Think, "I match every X queries".
39
40=cut
41
42has 'every' => (
43 is=>'ro',
44 isa=>'Int',
45 required=>1,
46);
47
48
49=head2 offset (Int)
50
51This is a number of queries from the start of all queries to offset the match
52counting mechanism. This is basically added to the L</every> attribute to
53identify a query as matching the interval we wish to define.
54
55=cut
56
57has 'offset' => (
58 is=>'ro',
59 isa=>'Int',
60 required=>1,
61 default=>0,
62);
63
64
65=head1 METHODS
66
67This module defines the following methods.
68
69=head2 matches ($query_count)
70
71Does the $query_count match the defined interval? Returns a Boolean.
72
73=cut
74
75sub matches {
76 my ($self, $query_count) = @_;
77 my $offset_count = $query_count - $self->offset;
78 return $offset_count % $self->every ? 0:1;
79}
80
81
82=head1 AUTHORS
83
84See L<DBIx::Class> for more information regarding authors.
85
86=head1 LICENSE
87
88You may distribute this code under the same terms as Perl itself.
89
90=cut
91
92
931;