File Coverage

blib/lib/Class/Workflow/Transition.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Class::Workflow::Transition;
4 1     1   1248 use Moose::Role;
  0            
  0            
5              
6             use Carp qw/croak/;
7              
8             requires "apply";
9              
10             sub derive_and_accept_instance {
11             my ( $self, $proto_instance, $attrs, @args ) = @_;
12              
13             croak "You must specify the next state of the instance"
14             unless $attrs->{state};
15              
16             my $state = $attrs->{state};
17              
18             my $instance = $proto_instance->derive(
19             transition => $self,
20             %$attrs,
21             );
22              
23             return $state->accept_instance( $instance, @args );
24             }
25              
26             __PACKAGE__;
27              
28             __END__
29              
30             =pod
31              
32             =head1 NAME
33              
34             Class::Workflow::Transition - A function over an instance.
35              
36             =head1 SYNOPSIS
37              
38             package MyTransition;
39             use Moose;
40             with 'Class::Workflow::Transition';
41              
42             =head1 DESCRIPTION
43              
44             This is the base role for transition implementations.
45              
46             B<every> transition object must comply to it's interface, and furthermore must
47             also use the C<derive_and_accept_instance> method to return a derived instance
48             at the end of the operation.
49              
50             =head1 METHODS
51              
52             =over 4
53              
54             =item derive_and_accept_instance $instance, \%attrs, @args
55              
56             This method calls C<< $instance->derive >> with the attrs, and then calls the
57             instance C<accept_instance> on the new instance's state.
58              
59             C<%attrs> B<must> contain the key C<state>, which should do the role
60             L<Class::Workflow::State>.
61              
62             @args are passed (along with the derived instance) to
63             L<Class::Workflow::State/accept_instance>.
64              
65             =back
66              
67             =head1 REQUIRED METHODS
68              
69             =over 4
70              
71             =item apply $insatnce, @args
72              
73             This method accepts a L<Class::Workflow::Instance> as it's first argument, and
74             is expected to call
75             C<< $self->derive_and_accept_instance( $instance, \%attrs, @args ) >>, with
76             C<%attrs> containing the state that the instance is being transferred to (it
77             doesn't have to be different than the current state).
78              
79             =back
80              
81             =cut
82              
83