line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Class::Workflow::Transition::Deterministic; |
4
|
1
|
|
|
1
|
|
2304
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Carp qw/croak/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has to_state => ( |
9
|
|
|
|
|
|
|
does => "Class::Workflow::State", |
10
|
|
|
|
|
|
|
is => "rw", |
11
|
|
|
|
|
|
|
required => 0, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# FIXME augment + inner |
15
|
|
|
|
|
|
|
requires "apply_body"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub apply { |
18
|
|
|
|
|
|
|
my ( $self, $instance, @args ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my ( $set_instance_attrs, @rv ) = $self->apply_body( $instance, @args ); |
21
|
|
|
|
|
|
|
$set_instance_attrs ||= {}; # should really die if it's bad |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $new_instance = $self->derive_and_accept_instance( |
24
|
|
|
|
|
|
|
$instance => { |
25
|
|
|
|
|
|
|
state => ( $self->to_state || croak "$self has no 'to_state'" ), |
26
|
|
|
|
|
|
|
%$set_instance_attrs, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
@args, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return wantarray ? ($new_instance, @rv) : $new_instance; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__PACKAGE__; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Class::Workflow::Transition::Deterministic - A transition which knows which |
43
|
|
|
|
|
|
|
state it leads to. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package MyTransition; |
48
|
|
|
|
|
|
|
use Moose; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
with qw/ |
51
|
|
|
|
|
|
|
Class::Workflow::Transition |
52
|
|
|
|
|
|
|
Class::Workflow::Deterministic |
53
|
|
|
|
|
|
|
/; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub apply_body { # instead of 'sub apply' |
56
|
|
|
|
|
|
|
# body |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# this may be changed to the following form in the future: |
60
|
|
|
|
|
|
|
augment apply => sub { |
61
|
|
|
|
|
|
|
# body |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This role provides a base role for transitions which know their target state. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
It overrides C<apply> with a default implementation that will derive an |
69
|
|
|
|
|
|
|
instance for you, setting C<state> automatically, appending the return value |
70
|
|
|
|
|
|
|
from C<apply_body> to that list. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
You should consume this role unless you need to determine the target state |
73
|
|
|
|
|
|
|
dynamically (probably not a good idea). |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 FIELDS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=over 4 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item to_state |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The target state of the transition. Should do L<Class::Workflow::State>. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 METHODS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over 4 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item apply |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
In scalar context returns the derived instance, in list caller also returns the |
92
|
|
|
|
|
|
|
remaining return value from C<apply_body>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 REQUIRED METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over 4 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item apply_body |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
The "inner" body of the function. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This method is always evaluated in list context, and is expected to return a |
105
|
|
|
|
|
|
|
hash reference of overridden fields as the first value in that list. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
In the future instead of defining C<apply_body> you will do: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
augment apply => sub { |
110
|
|
|
|
|
|
|
# body |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
And this role's C<apply> will really use C<inner()>. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|