Cron::Sequencer::Parser
my $crontab = Cron::Sequencer::Parser->new("/path/to/crontab");
This class parses a single crontab and converts it to a form that Cron::Sequencer can use.
Cron::Sequencer
new takes a single argument representing a crontab file to parse. Various formats are supported:
new
A file on disk
The contents of the crontab (as a single string of multiple lines)
The contents of a crontab, as a single string of multiple lines. (Not a reference to a scalar containing this)
A file on disk. If both crontab and source are provided, then source is only used as the name of the crontab in output (and errors). No attempt is made to read the file from disk.
crontab
source
Default values for environment variables set in the crontab, as a reference to an array of strings in the form KEY=VALUE. See below for examples.
KEY=VALUE
Lines in the crontab to completely ignore, as an array of integers. These are processed as the first step in the parser, so it's possible to ignore all of
command entries (particularly "chatty" entries such as * * * * *)
* * * * *
setting environment variables
lines with syntax errors that otherwise would abort the parse
This is the most flexible format. At least one of source or crontab must be specified.
The only way to provide env or ignore options is to pass a hashref.
env
ignore
Returns a list of the crontab's command entries as data structures. Used internally by Cron::Sequencer and subject to change.
For this input
POETS=Friday 30 12 * * * lunch!
with default constructor options this code:
use Cron::Sequencer; use Data::Dump; my $crontab = Cron::Sequencer->new({source => "reminder"}); dd([$crontab->sequence(45000, 131400)]);
would generate this output:
[ [ { command => "lunch!", env => { POETS => "Friday" }, file => "reminder", lineno => 2, time => 45000, unset => ["HUMP"], when => "30 12 * * *", }, ], ]
If we specify two environment variables:
my $crontab = Cron::Sequencer->new({source => "reminder", env => [ "POETS=Friday", "HUMP=Wednesday" ]});
the output is:
[ [ { command => "lunch!", env => undef, file => "reminder", lineno => 2, time => 45000, unset => ["HUMP"], when => "30 12 * * *", }, ], ]
(because POETS matches the default, but HUMP was never set in the crontab)
POETS
HUMP
If we ignore the first line:
my $crontab = Cron::Sequencer->new({source => "reminder", ignore => [1]}); [ [ { command => "lunch!", env => undef, file => "reminder", lineno => 2, time => 45000, unset => undef, when => "30 12 * * *", }, ], ]
we ignore the line in the crontab that sets the environment variable.
For completeness, if we ignore the line that declares an event:
my $crontab = Cron::Sequencer->new({source => "reminder", ignore => [2]});
there's nothing to output:
[]
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. If you would like to contribute documentation, features, bug fixes, or anything else then please raise an issue / pull request:
https://github.com/Humanstate/cron-sequencer
Nicholas Clark - nick@ccl4.org
nick@ccl4.org
To install Cron::Sequencer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cron::Sequencer
CPAN shell
perl -MCPAN -e shell install Cron::Sequencer
For more information on module installation, please visit the detailed CPAN module installation guide.