line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2001 Abhijit Menon-Sen |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Set::Crontab; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8091
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
796
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '1.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub _expand |
12
|
|
|
|
|
|
|
{ |
13
|
11
|
|
|
11
|
|
11
|
my (@list, @and, @not); |
14
|
11
|
|
|
|
|
13
|
my ($self, $spec, $range) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# 1,2-4,*/3,!13,>9,<15 |
17
|
11
|
|
|
|
|
36
|
foreach (split /,/, $spec) { |
18
|
29
|
|
|
|
|
26
|
my @pick; |
19
|
29
|
100
|
|
|
|
70
|
my $step = $1 if s#/(\d+)$##; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# 0+"01" == 1 |
22
|
29
|
100
|
|
|
|
228
|
if (/^(\d+)$/) { push @pick, 0+$1; } |
|
10
|
100
|
|
|
|
23
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
23
|
3
|
|
|
|
|
10
|
elsif (/^\*$/) { push @pick, @$range; } |
24
|
8
|
|
|
|
|
20
|
elsif (/^(\d+)-(\d+)$/) { push @pick, 0+$1..0+$2; } |
25
|
4
|
|
|
|
|
11
|
elsif (/^!(\d+)$/) { push @not, "\$_ != 0+$1"; } |
26
|
4
|
|
|
|
|
25
|
elsif (/^([<>])(\d+)$/) { push @and, "\$_ $1 0+$2"; } |
27
|
|
|
|
|
|
|
|
28
|
29
|
100
|
|
|
|
49
|
if ($step) { |
29
|
2
|
|
|
|
|
4
|
my $i; |
30
|
2
|
100
|
|
|
|
4
|
@pick = grep { defined $_ if $i++ % $step == 0 } @pick; |
|
22
|
|
|
|
|
77
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
29
|
|
|
|
|
67
|
push @list, @pick; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
11
|
100
|
|
|
|
81
|
if (@and) { |
37
|
2
|
|
|
|
|
5
|
my $and = join q{ && }, @and; |
38
|
2
|
100
|
|
|
|
4
|
push @list, grep { defined $_ if eval $and } @$range; |
|
22
|
|
|
|
|
1195
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
11
|
100
|
|
|
|
25
|
if (@not) { |
42
|
4
|
|
|
|
|
9
|
my $not = join q{ && }, @not; |
43
|
4
|
100
|
|
|
|
13
|
@list = grep { defined $_ if eval $not } (@list ? @list : @$range); |
|
33
|
100
|
|
|
|
1523
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
11
|
|
|
|
|
34
|
@list = sort { $a <=> $b } @list; |
|
127
|
|
|
|
|
121
|
|
47
|
11
|
|
|
|
|
46
|
return \@list; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _initialise |
51
|
|
|
|
|
|
|
{ |
52
|
11
|
|
|
11
|
|
17
|
my ($self, $spec, $range) = @_; |
53
|
11
|
50
|
|
|
|
23
|
return undef unless ref($self); |
54
|
|
|
|
|
|
|
|
55
|
11
|
50
|
33
|
|
|
50
|
croak "Usage: ".__PACKAGE__."->new(\$spec, [\@range])" |
56
|
|
|
|
|
|
|
unless defined $spec && ref($range) eq "ARRAY"; |
57
|
|
|
|
|
|
|
|
58
|
11
|
|
|
|
|
25
|
$self->{LIST} = $self->_expand($spec, $range); |
59
|
11
|
|
|
|
|
15
|
$self->{HASH} = {map {$_ => 1} @{$self->{LIST}}}; |
|
76
|
|
|
|
|
163
|
|
|
11
|
|
|
|
|
19
|
|
60
|
|
|
|
|
|
|
|
61
|
11
|
|
|
|
|
46
|
return $self; |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new |
65
|
|
|
|
|
|
|
{ |
66
|
11
|
|
|
11
|
1
|
104
|
my $class = shift; |
67
|
11
|
|
33
|
|
|
57
|
my $self = bless {}, ref($class) || $class; |
68
|
11
|
|
|
|
|
27
|
return $self->_initialise(@_); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub contains |
72
|
|
|
|
|
|
|
{ |
73
|
15
|
|
|
15
|
1
|
55
|
my ($self, $num) = @_; |
74
|
|
|
|
|
|
|
|
75
|
15
|
50
|
33
|
|
|
71
|
croak "Usage: \$set->contains(\$num)" unless ref($self) && defined $num; |
76
|
15
|
|
|
|
|
70
|
return exists $self->{HASH}{$num}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub list |
80
|
|
|
|
|
|
|
{ |
81
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
6
|
croak "Usage: \$set->list()" unless ref($self); |
84
|
1
|
|
|
|
|
1
|
return @{$self->{LIST}}; |
|
1
|
|
|
|
|
10
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |