| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | package Class::Workflow::State::TransitionHash; | ||||||||||||||||||||
| 4 | 5 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 5 | ▶ | use Carp qw/croak/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 5 | with qw/ | |||||||||||||||||||
| 9 | Class::Workflow::State | ||||||||||||||||||||
| 10 | Class::Workflow::State::TransitionSet | ||||||||||||||||||||
| 11 | /; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | has transition_hash => ( | ||||||||||||||||||||
| 14 | isa => "HashRef", | ||||||||||||||||||||
| 15 | is => "rw", | ||||||||||||||||||||
| 16 | 17 | ▶ | default => sub { {} }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 5 | ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 17 | ▶ | after "BUILDALL" => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 17 | my $self = shift; | |||||||||||||||||||
| 21 | 17 | $self->_reindex_hash; | |||||||||||||||||||
| 22 | 5 | }; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 21 | ▶ | sub _reindex_hash { | ||||||||||||||||||
|
Subroutine
_reindex_hash: called CC=5 SCAR=17.5
| |||||||||||||||||||||
| 25 | 21 | my $self = shift; | |||||||||||||||||||
| 26 | 21 | my @transitions = $self->transitions; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 21 | for ( @transitions ) { | |||||||||||||||||||
| 29 | 24 | ▶ | blessed($_) | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$_ || ''
MC/DC0%0/1
$_ || ''
$_
Truth table0%0/2
A
A= $_
| |||||||||||||||||||||
| 30 | or croak (($_||'') . " is not an object"); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 24 | ▶ | $_->can("name") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | or croak "All transitions registered with a hash based state must know their own name"; | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 21 | $self->transition_hash({ map { $_->name => $_ } @transitions }); | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 25 | ▶ | after transitions => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 40 | 25 | my ( $self, @transitions ) = @_; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 25 | ▶ | if ( @transitions ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 3 | $self->_reindex_hash; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 5 | }; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | ▶ | after clear_transitions => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||
| 49 | 0 | $self->transition_hash({}); | |||||||||||||||||||
| 50 | 5 | }; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | ▶ | after qw/remove_transitions add_transitions/ => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | my $self = shift; | |||||||||||||||||||
| 54 | 1 | $self->_reindex_hash; | |||||||||||||||||||
| 55 | 5 | }; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 11 | ▶ | around has_transition => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 58 | 11 | my $next = shift; | |||||||||||||||||||
| 59 | 11 | my ( $self, $transition ) = @_; | |||||||||||||||||||
| 60 | 11 | ▶ | if ( blessed( $transition ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 9 | return $self->$next( $transition ); | |||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||
| 63 | 2 | return exists $self->transition_hash->{$transition}; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 5 | }; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | ▶ | around has_transitions => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||
| 68 | 1 | my $next = shift; | |||||||||||||||||||
| 69 | 1 | my ( $self, @transitions ) = @_; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | foreach my $t ( @transitions ) { | |||||||||||||||||||
| 72 | 0 | ▶ | return unless $self->has_transition( $t ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | return 1; | |||||||||||||||||||
| 76 | 5 | }; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 8 | ▶ | sub get_transition { | ||||||||||||||||||
|
Subroutine
get_transition: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 79 | 8 | my ( $self, $transition ) = @_; | |||||||||||||||||||
| 80 | 8 | ▶ | return ( blessed($transition) ? $transition : $self->transition_hash->{$transition} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | sub get_transitions { | ||||||||||||||||||
|
Subroutine
get_transitions: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 84 | 0 | my ( $self, @transitions ) = @_; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | if ( @transitions ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | return map { $self->get_transition( $_ ) } @transitions; | |||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||
| 89 | 0 | return $self->transitions; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 5 | __PACKAGE__; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||