Commit | Line | Data |
25e4a0c4 |
1 | package DBIx::Class::Schema::Job; |
2 | |
3 | use Moose; |
4 | use Moose::Util::TypeConstraints; |
5 | |
6 | =head1 NAME |
7 | |
8 | DBIx::Class::Schema::Job; A job associated with a Schema |
9 | |
10 | =head1 SYNOPSIS |
11 | |
12 | The 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 | |
19 | This is a base class intended to hold code that get's executed by the schema |
20 | according to rules known to the schema. Subclassers may wish to override how |
21 | the L</runs> attribute is defined in order to create custom behavior. |
22 | |
23 | =head1 SUBTYPES |
24 | |
25 | This package defines the following subtypes |
26 | |
27 | =head2 Handler |
28 | |
29 | A coderef based type that the job runs when L</execute> is called. |
30 | |
31 | =cut |
32 | |
33 | subtype 'DBIx::Class::Schema::Job::Handler' |
34 | => as 'CodeRef'; |
35 | |
36 | coerce '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 | |
49 | This package defines the following attributes. |
50 | |
51 | =head2 runs |
52 | |
53 | This 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 | |
58 | has 'runs' => ( |
59 | is=>'ro', |
60 | isa=>'DBIx::Class::Schema::Job::Handler', |
61 | coerce=>1, |
62 | required=>1, |
63 | ); |
64 | |
65 | |
66 | =head1 METHODS |
67 | |
68 | This module defines the following methods. |
69 | |
70 | =head2 execute ($schema, $query_interval) |
71 | |
72 | Method called by the L<DBIx::Class::Schema> when it wants a given job to run. |
73 | |
74 | =cut |
75 | |
76 | sub execute { |
77 | return $_[0]->runs->(@_); |
78 | } |
79 | |
80 | |
81 | =head1 AUTHORS |
82 | |
83 | See L<DBIx::Class> for more information regarding authors. |
84 | |
85 | =head1 LICENSE |
86 | |
87 | You may distribute this code under the same terms as Perl itself. |
88 | |
89 | =cut |
90 | |
91 | |
92 | 1; |