blib/lib/Set/Crontab.pm

filter: Statementstmt 100% 56 / 56 Branchbran 85.2% 29 / 34 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 85.3% 99 / 116 CC 22 SCAR 22.1
CC
22
Cov
89%
_expand
15.0
_initialise
4.3
contains
3.5
CRAP 9.1
↑ Summary
1 # Copyright 2001 Abhijit Menon-Sen <ams@toroid.org>
2  
3 package Set::Crontab;
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = '1.03';
10  
11 sub _expand
12 11 ▶{
Subroutine _expand: called CC=15 SCAR=27.1
13 11 my (@list, @and, @not);
14 11 my ($self, $spec, $range) = @_;
15  
16 # 1,2-4,*/3,!13,>9,<15
17 11 foreach (split /,/, $spec) {
18 29 my @pick;
19 29 ▶ my $step = $1 if s#/(\d+)$##;
Branch: 1 branch
BranchTrueFalseTotal
if s[/(\d+)$][] 2 27 29
20  
21 # 0+"01" == 1
22 29 ▶ if (/^(\d+)$/) { push @pick, 0+$1; }
Branch: 5 branches
BranchTrueFalseTotal
if (/^(\d+)$/) { } 10 19 29
elsif (/^\*$/) { } 3 16 19
elsif (/^(\d+)-(\d+)$/) { } 8 8 16
elsif (/^!(\d+)$/) { } 4 4 8
elsif (/^([<>])(\d+)$/) { } 4 0 4
23 3 elsif (/^\*$/) { push @pick, @$range; }
24 8 elsif (/^(\d+)-(\d+)$/) { push @pick, 0+$1..0+$2; }
25 4 elsif (/^!(\d+)$/) { push @not, "\$_ != 0+$1"; }
26 4 elsif (/^([<>])(\d+)$/) { push @and, "\$_ $1 0+$2"; }
27  
28 29 ▶ if ($step) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step) 2 27 29
29 2 my $i;
30 2 ▶ @pick = grep { defined $_ if $i++ % $step == 0 } @pick;
Branch: 1 branch
BranchTrueFalseTotal
if $i++ % $step == 0 10 12 22
31 }
32  
33 29 push @list, @pick;
34 }
35  
36 11 ▶ if (@and) {
Branch: 1 branch
BranchTrueFalseTotal
if (@and) 2 9 11
37 2 my $and = join q{ && }, @and;
38 2 ▶ push @list, grep { defined $_ if eval $and } @$range;
Branch: 1 branch
BranchTrueFalseTotal
if eval $and 8 14 22
39 }
40  
41 11 ▶ if (@not) {
Branch: 1 branch
BranchTrueFalseTotal
if (@not) 4 7 11
42 4 my $not = join q{ && }, @not;
43 4 ▶ @list = grep { defined $_ if eval $not } (@list ? @list : @$range);
Branch: 2 branches
BranchTrueFalseTotal
if eval $not 29 4 33
@list ? : 3 1 4
44 }
45  
46 11 @list = sort { $a <=> $b } @list;
47 11 return \@list;
48 }
49  
50 sub _initialise
51 11 ▶{
Subroutine _initialise: called CC=4 SCAR=14.6
52 11 my ($self, $spec, $range) = @_;
53 11 ▶ return undef unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 11 11
54  
55 11 ▶ croak "Usage: ".__PACKAGE__."->new(\$spec, [\@range])"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec and ref $range eq "ARRAY" 0 11 11
Condition33%1/3
defined $spec and ref $range eq "ARRAY"
!ll&&!rl&&r
0011
MC/DC0%0/2
defined $spec and ref $range eq "ARRAY"
defined $spec ref $range eq "ARRAY"
Truth table33%1/3
A and B
A= defined $specB= ref $range eq "ARRAY"
ABresult
0X0
100
111
56 unless defined $spec && ref($range) eq "ARRAY";
57  
58 11 $self->{LIST} = $self->_expand($spec, $range);
59 11 $self->{HASH} = {map {$_ => 1} @{$self->{LIST}}};
60  
61 11 return $self;
62 };
63  
64 sub new
65 11 ▶{
Subroutine new: called CC=2 SCAR=7.6
Pod documented
66 11 my $class = shift;
67 11 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0110
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
68 11 return $self->_initialise(@_);
69 }
70  
71 sub contains
72 15 ▶{
Subroutine contains: called CC=3 SCAR=12.5
Pod documented
73 15 my ($self, $num) = @_;
74  
75 15 ▶ croak "Usage: \$set->contains(\$num)" unless ref($self) && defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self and defined $num 0 15 15
Condition33%1/3
ref $self and defined $num
!ll&&!rl&&r
0015
MC/DC0%0/2
ref $self and defined $num
ref $self defined $num
Truth table33%1/3
A and B
A= ref $selfB= defined $num
ABresult
0X0
100
111
76 15 return exists $self->{HASH}{$num};
77 }
78  
79 sub list
80 1 ▶{
Subroutine list: called CC=2 SCAR=7.0
Pod documented
81 1 my $self = shift;
82  
83 1 ▶ croak "Usage: \$set->list()" unless ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
84 1 return @{$self->{LIST}};
85 }
86  
87 1 1;
88 __END__
↑ Summary