| 1 | package Workflow::Persister; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use 5.013002; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 34 | ▶ | use parent qw( Workflow::Base ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 34 | ▶ | use Workflow::Exception qw( persist_error ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 34 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 34 | ▶ | use constant DEFAULT_ID_LENGTH => 8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 34 | $Workflow::Persister::VERSION = '2.12'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 34 | my @FIELDS = qw( name class | |||||||||||||||||||||||||||
| 15 | use_random use_uuid | ||||||||||||||||||||||||||||
| 16 | workflow_id_generator history_id_generator ); | ||||||||||||||||||||||||||||
| 17 | 34 | __PACKAGE__->mk_accessors(@FIELDS); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 22 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 22 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 21 | 22 | for (@FIELDS) { | |||||||||||||||||||||||||||
| 22 | 132 | ▶ | $self->$_( $params->{$_} ) if ( $params->{$_} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 22 | ▶ | unless ( $self->use_random ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 21 | $self->use_random('no'); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 22 | ▶ | unless ( $self->use_uuid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 21 | $self->use_uuid('no'); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 22 | $self->log->info( "Initializing persister '", $self->name, "'" ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ######################################## | ||||||||||||||||||||||||||||
| 34 | # COMMON GENERATOR ASSIGNMENTS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 24 | ▶ | sub assign_generators { | ||||||||||||||||||||||||||
|
Subroutine
assign_generators: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 24 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 38 | 24 | ▶ | $params ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params ||= {}
MC/DC100%1/1
$params ||= {}
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 24 | my ( $wf_gen, $history_gen ); | |||||||||||||||||||||||||||
| 41 | 24 | ▶ | if ( $self->use_uuid eq 'yes' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 42 | 2 | $self->log->debug("Assigning UUID generators by request"); | |||||||||||||||||||||||||||
| 43 | 2 | ( $wf_gen, $history_gen ) = $self->init_uuid_generators($params); | |||||||||||||||||||||||||||
| 44 | } elsif ( $self->use_random eq 'yes' ) { | ||||||||||||||||||||||||||||
| 45 | 5 | $self->log->debug("Assigning random ID generators by request"); | |||||||||||||||||||||||||||
| 46 | 5 | ( $wf_gen, $history_gen ) = $self->init_random_generators($params); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 22 | ▶ | if ( $wf_gen and $history_gen ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$wf_gen and $history_gen
MC/DC50%1/2
$wf_gen and $history_gen
$wf_gen
$history_gen
Truth table66%2/3
A and B
A= $wf_genB= $history_gen
| |||||||||||||||||||||||||||||
| 49 | 5 | $self->workflow_id_generator($wf_gen); | |||||||||||||||||||||||||||
| 50 | 5 | $self->history_id_generator($history_gen); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 21 | ▶ | sub init_random_generators { | ||||||||||||||||||||||||||
|
Subroutine
init_random_generators: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 21 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 56 | 21 | ▶ | my $length = $params->{id_length} || DEFAULT_ID_LENGTH; | ||||||||||||||||||||||||||
|
Condition50%1/2
$params->{'id_length'} || 8
MC/DC0%0/1
$params->{'id_length'} || 8
$params->{'id_length'}
Truth table50%1/2
A
A= $params->{'id_length'}
| |||||||||||||||||||||||||||||
| 57 | try { | ||||||||||||||||||||||||||||
| 58 | 21 | require Workflow::Persister::RandomId; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 21 | catch ($msg) { | |||||||||||||||||||||||||||
| 61 | 1 | my $logmsg = ($msg =~ s/\\n/ /gr); | |||||||||||||||||||||||||||
| 62 | 1 | $self->log->error($logmsg); | |||||||||||||||||||||||||||
| 63 | 1 | die $msg; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 20 | my $generator | |||||||||||||||||||||||||||
| 66 | = Workflow::Persister::RandomId->new( { id_length => $length } ); | ||||||||||||||||||||||||||||
| 67 | 20 | return ( $generator, $generator ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | sub init_uuid_generators { | ||||||||||||||||||||||||||
|
Subroutine
init_uuid_generators: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 2 | my ( $self, $params ) = @_; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | try { | ||||||||||||||||||||||||||||
| 74 | require Workflow::Persister::UUID | ||||||||||||||||||||||||||||
| 75 | 2 | } | |||||||||||||||||||||||||||
| 76 | 2 | catch ($msg) { | |||||||||||||||||||||||||||
| 77 | 1 | my $logmsg = ($msg =~ s/\\n/ /gr); | |||||||||||||||||||||||||||
| 78 | 1 | $self->log->error($logmsg); | |||||||||||||||||||||||||||
| 79 | 1 | die $msg; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 1 | my $generator = Workflow::Persister::UUID->new(); | |||||||||||||||||||||||||||
| 82 | 1 | return ( $generator, $generator ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | ######################################## | ||||||||||||||||||||||||||||
| 86 | # INTERFACE METHODS | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | ▶ | sub create_workflow { | ||||||||||||||||||||||||||
|
Subroutine
create_workflow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 1 | my ( $self, $wf ) = @_; | |||||||||||||||||||||||||||
| 90 | 1 | persist_error "Persister '", ref($self), "' must implement ", | |||||||||||||||||||||||||||
| 91 | "'create_workflow()'"; | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | ▶ | sub update_workflow { | ||||||||||||||||||||||||||
|
Subroutine
update_workflow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 1 | my ( $self, $wf ) = @_; | |||||||||||||||||||||||||||
| 96 | 1 | persist_error "Persister '", ref($self), "' must implement ", | |||||||||||||||||||||||||||
| 97 | "'update_workflow()'"; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | ▶ | sub fetch_workflow { | ||||||||||||||||||||||||||
|
Subroutine
fetch_workflow: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 1 | my ( $self, $wf_id ) = @_; | |||||||||||||||||||||||||||
| 102 | 1 | persist_error "Persister '", ref($self), "' must implement ", | |||||||||||||||||||||||||||
| 103 | "'fetch_workflow()'"; | ||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | ▶ | sub create_history { | ||||||||||||||||||||||||||
|
Subroutine
create_history: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 1 | my ( $self, $wf, @history ) = @_; | |||||||||||||||||||||||||||
| 108 | 1 | persist_error "Persister '", ref($self), "' must implement ", | |||||||||||||||||||||||||||
| 109 | "'create_history()'"; | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 1 | ▶ | sub fetch_history { | ||||||||||||||||||||||||||
|
Subroutine
fetch_history: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 1 | my ( $self, $wf ) = @_; | |||||||||||||||||||||||||||
| 114 | 1 | persist_error "Persister '", ref($self), "' must implement ", | |||||||||||||||||||||||||||
| 115 | "'fetch_history()'"; | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # Only required for DBI persisters. | ||||||||||||||||||||||||||||
| 119 | 8 | ▶ | sub commit_transaction { | ||||||||||||||||||||||||||
|
Subroutine
commit_transaction: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 8 | return; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub rollback_transaction { | ||||||||||||||||||||||||||
|
Subroutine
rollback_transaction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | return; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 34 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||