removed query count stuff from trunk so we can play with this on a branch instead
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Schema / Job.pm
CommitLineData
25e4a0c4 1package DBIx::Class::Schema::Job;
2
3use Moose;
4use Moose::Util::TypeConstraints;
5
6=head1 NAME
7
8DBIx::Class::Schema::Job; A job associated with a Schema
9
10=head1 SYNOPSIS
11
12The following example creates a new job and then executes it.
13
14 my $job = DBIx::Class::Schema->new(runs => sub { print 'did job'});
15 $job->execute; # 'did job' -> STDOUT
16
17=head1 DESCRIPTION
18
19This is a base class intended to hold code that get's executed by the schema
20according to rules known to the schema. Subclassers may wish to override how
21the L</runs> attribute is defined in order to create custom behavior.
22
23=head1 SUBTYPES
24
25This package defines the following subtypes
26
27=head2 Handler
28
29A coderef based type that the job runs when L</execute> is called.
30
31=cut
32
33subtype 'DBIx::Class::Schema::Job::Handler'
34 => as 'CodeRef';
35
36coerce 'DBIx::Class::Schema::Job::Handler'
37 => from 'Str'
38 => via {
39 my $handler_method = $_;
40 sub {
41 my $job = shift @_;
42 my $target = shift @_;
43 $target->$handler_method($job, @_);
44 };
45 };
46
47=head1 ATTRIBUTES
48
49This package defines the following attributes.
50
51=head2 runs
52
53This is a coderef which is de-reffed by L</execute> and is passed the job object
54(ie $self), and any additional arguments passed to L</execute>
55
56=cut
57
58has 'runs' => (
59 is=>'ro',
60 isa=>'DBIx::Class::Schema::Job::Handler',
61 coerce=>1,
62 required=>1,
63);
64
65
66=head1 METHODS
67
68This module defines the following methods.
69
70=head2 execute ($schema, $query_interval)
71
72Method called by the L<DBIx::Class::Schema> when it wants a given job to run.
73
74=cut
75
76sub execute {
77 return $_[0]->runs->(@_);
78}
79
80
81=head1 AUTHORS
82
83See L<DBIx::Class> for more information regarding authors.
84
85=head1 LICENSE
86
87You may distribute this code under the same terms as Perl itself.
88
89=cut
90
91
921;