line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Class::Workflow::Context; |
4
|
2
|
|
|
2
|
|
4781
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has stash => ( |
7
|
|
|
|
|
|
|
isa => "HashRef", |
8
|
|
|
|
|
|
|
is => "rw", |
9
|
|
|
|
|
|
|
default => sub { {} }, |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__END__ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=pod |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Class::Workflow::Context - The context in which a transition is being applied |
21
|
|
|
|
|
|
|
(optional). |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Class::Workflow::Context; # or a subclass or something |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $c = Class::Workflow::Context->new( ... ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $new_instance = $transition->apply( $instance, $c ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
If you need to pass arbitrary arguments to the workflow, a context object will |
34
|
|
|
|
|
|
|
usually help. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This specific context object provides C<stash>, a writable hash which is |
37
|
|
|
|
|
|
|
essentially free-for-all. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
L<Class::Workflow::Context> doesn't provide much and should generally be |
40
|
|
|
|
|
|
|
subclassed. It is designed to resemble the L<Catalyst> context object. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Usage of a context object is completely optional, and L<Class::Workflow>'s |
43
|
|
|
|
|
|
|
other core objects (L<Class::Workflow::State>, L<Class::Workflow::Transition>, |
44
|
|
|
|
|
|
|
and L<Class::Workflow::Instance> really don't care about context objects at |
45
|
|
|
|
|
|
|
all). |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 STYLE GUIDE |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
When writing a workflow that governs a web application, for example, |
50
|
|
|
|
|
|
|
transitions will generally expect explicit parameters, having to do with their |
51
|
|
|
|
|
|
|
specific responsibility, and more "global" parameters, like on behalf of which |
52
|
|
|
|
|
|
|
user is this transition being applied. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
A context object is a way to provide a standard set of facilities that every |
55
|
|
|
|
|
|
|
transition can expect. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub apply { |
58
|
|
|
|
|
|
|
my ( $self, $instance, $c, %args ) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $arg = $args{arg_i_care_about}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $user = $c->user; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
... |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Conceptually C<$c> is akin to the environment the workflow is being used in, |
68
|
|
|
|
|
|
|
wheras C<%args> are the actual parameters. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Note that this is only one of many possible conventions you can use in your |
71
|
|
|
|
|
|
|
workflow system. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The context should probably not be mutated by the workflow itself. That's what |
74
|
|
|
|
|
|
|
the workflow instance is for. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 CONTEXT ROLES |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
You are encouraged to create roles for additional paremeters in the context, |
79
|
|
|
|
|
|
|
and compose them together into the final workflow class instead of relying on |
80
|
|
|
|
|
|
|
C<stash>. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This provides a more structured approach, and lets you use C<lazy_build> in the |
83
|
|
|
|
|
|
|
attributes cleanly. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
You could also apply runtime roles to the workflow class for a more dynamic and |
86
|
|
|
|
|
|
|
flexible solution. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 FIELDS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 4 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item stash |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Just a simple hash reference. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|