blib/lib/Event/ExecFlow/Job/Code.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 52 CC 2 SCAR 9.8
CC
2
Cov
0%
execute
6.0
get_exec_type
2.0
get_type
2.0
CRAP 2.7
1 package Event::ExecFlow::Job::Code;
2  
3 use base qw( Event::ExecFlow::Job );
4  
5 use strict;
6  
7 sub get_exec_type { "sync" }
8 sub get_type { "code" }
9  
10 sub get_code { shift->{code} }
11 sub set_code { shift->{code} = $_[1] }
12  
13 sub new {
14 my $class = shift;
15 my %par = @_;
16 my ($code) = $par{'code'};
17  
18 my $self = $class->SUPER::new(@_);
19  
20 $self->set_code($code);
21  
22 return $self;
23 }
24  
25 sub execute {
26 my $self = shift;
27
28 my $code = $self->get_code;
29
30 eval { $code->($self) };
31 $self->set_error_message($@) if $@;
32
33 $self->execution_finished;
34
35 1;
36 }
37  
38 sub cancel {
39 my $self = shift;
40  
41 $self->set_cancelled(1);
42  
43 1;
44 }
45  
46 sub pause_job {
47 my $self = shift;
48  
49 1;
50 }
51  
52 sub backup_state {
53 my $self = shift;
54
55 my $data_href = $self->SUPER::backup_state();
56
57 delete $data_href->{code};
58
59 return $data_href;
60 }
61  
62 1;
63  
64 __END__