| 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
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # 0+"01" == 1 | ||||||||||||||||||||||||||||
| 22 | 29 | ▶ | if (/^(\d+)$/) { push @pick, 0+$1; } | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 29 | 2 | my $i; | |||||||||||||||||||||||||||
| 30 | 2 | ▶ | @pick = grep { defined $_ if $i++ % $step == 0 } @pick; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 29 | push @list, @pick; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 11 | ▶ | if (@and) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 2 | my $and = join q{ && }, @and; | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | push @list, grep { defined $_ if eval $and } @$range; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 11 | ▶ | if (@not) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 4 | my $not = join q{ && }, @not; | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | @list = grep { defined $_ if eval $not } (@list ? @list : @$range); | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 11 | ▶ | croak "Usage: ".__PACKAGE__."->new(\$spec, [\@range])" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $spec and ref $range eq "ARRAY"
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"
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $self and defined $num
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 84 | 1 | return @{$self->{LIST}}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 1 | 1; | |||||||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||||||||