| 1 | #!/usr/bin/perl | ||||||||||
| 2 | |||||||||||
| 3 | package Class::Workflow::Transition::Simple; | ||||||||||
| 4 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use overload '""' => "stringify", fallback => 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # FIXME with Class::Workflow::Transition should not be necessary | ||||||||||
| 9 | 5 | with qw/ | |||||||||
| 10 | Class::Workflow::Transition | ||||||||||
| 11 | Class::Workflow::Transition::Deterministic | ||||||||||
| 12 | Class::Workflow::Transition::Strict | ||||||||||
| 13 | Class::Workflow::Transition::Validate::Simple | ||||||||||
| 14 | /; | ||||||||||
| 15 | |||||||||||
| 16 | 5 | has name => ( | |||||||||
| 17 | isa => "Str", | ||||||||||
| 18 | is => "rw", | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 37 | ▶ | sub stringify { | ||||||||
|
Subroutine
stringify: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||
| 22 | 37 | my $self = shift; | |||||||||
| 23 | 37 | ▶ | if ( defined( my $name = $self->name ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 37 | return $name; | |||||||||
| 25 | } | ||||||||||
| 26 | 0 | return overload::StrVal($_[0]); | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | has misc => ( | ||||||||||
| 30 | isa => "HashRef", | ||||||||||
| 31 | is => "rw", | ||||||||||
| 32 | 24 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 5 | auto_deref => 1, | |||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | has body => ( | ||||||||||
| 37 | isa => "CodeRef", | ||||||||||
| 38 | is => "rw", | ||||||||||
| 39 | 21 | ▶ | default => sub { sub { return () } }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 5 | ); | |||||||||
| 41 | |||||||||||
| 42 | has set_fields => ( | ||||||||||
| 43 | isa => "HashRef", | ||||||||||
| 44 | is => "rw", | ||||||||||
| 45 | 23 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 5 | ); | |||||||||
| 47 | |||||||||||
| 48 | # if set_fields is set it overrides body_sets_fields | ||||||||||
| 49 | 5 | has body_sets_fields => ( | |||||||||
| 50 | isa => "Bool", | ||||||||||
| 51 | is => "rw", | ||||||||||
| 52 | default => 0, | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | 10 | ▶ | sub apply_body { | ||||||||
|
Subroutine
apply_body: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 56 | 10 | my ( $self, $instance, @args ) = @_; | |||||||||
| 57 | 10 | my $body = $self->body; | |||||||||
| 58 | |||||||||||
| 59 | # if we have a predefined set of fields | ||||||||||
| 60 | 10 | ▶ | unless ( $self->body_sets_fields ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | return ( | ||||||||||
| 62 | 7 | $self->set_fields, | |||||||||
| 63 | $self->$body( $instance, @args ), | ||||||||||
| 64 | ); | ||||||||||
| 65 | } else { | ||||||||||
| 66 | # otherwise let the body control everything | ||||||||||
| 67 | 3 | return $self->$body( $instance, @args ); | |||||||||
| 68 | } | ||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 5 | __PACKAGE__; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||