File Coverage

blib/lib/Event/ExecFlow/Scheduler/SimpleMax.pm
Criterion Covered Total %
statement 25 27 92.5
branch 6 6 100.0
condition n/a
subroutine 7 9 77.7
pod 0 7 0.0
total 38 49 77.5


line stmt bran cond sub pod time code
1             package Event::ExecFlow::Scheduler::SimpleMax;
2              
3 1     1   3069 use strict;
  1         3  
  1         47  
4 1     1   6 use base qw ( Event::ExecFlow::Scheduler );
  1         1  
  1         615  
5              
6 20     20 0 396 sub get_max { shift->{max} }
7 20     20 0 77 sub get_cnt { shift->{cnt} }
8              
9 0     0 0 0 sub set_max { shift->{max} = $_[1] }
10 0     0 0 0 sub set_cnt { shift->{cnt} = $_[1] }
11              
12             sub new {
13 1     1 0 445 my $class = shift;
14 1         3 my %par = @_;
15 1         2 my ($max) = $par{'max'};
16              
17 1         6 return bless {
18             max => $max,
19             cnt => 0,
20             }, $class;
21             }
22              
23             sub schedule_job {
24 20     20 0 41 my $self = shift;
25 20         158 my ($job) = @_;
26              
27 20         42 my $state;
28 20 100       59 if ( $self->get_cnt >= $self->get_max ) {
    100          
29 7         44 $state = 'sched-blocked';
30             }
31             elsif ( $job->get_type ne 'group' ) {
32 11         25 ++$self->{cnt};
33 11         42 $state = 'ok';
34             }
35             else {
36 2         10 $state = 'ok';
37             }
38            
39 20         70 return $state;
40             }
41              
42             sub job_finished {
43 13     13 0 28 my $self = shift;
44 13         19 my ($job) = @_;
45 13 100       60 --$self->{cnt} if $job->get_type ne 'group';
46 13         34 1;
47             }
48              
49             1;
50              
51             __END__