DynGig-CLI
view release on metacpan or search on metacpan
lib/DynGig/CLI/Schedule/Period.pm view on Meta::CPAN
use constant DAY => 86400;
$| ++;
=head1 SYNOPSIS
$exe B<--help>
$exe [B<--timezone> zone] [B<--grep> pattern] [B<--config> file]
[B<--now> time] B<--calendar> year/month
$exe [B<--timezone> zone] [B<--grep> pattern] [B<--config> file]
[B<--now> time] B<--days> days
$exe [B<--timezone> zone] [B<--config> file] [B<--now> time]
=cut
sub main
{
my ( $class, %option ) = @_;
map { croak "$_ not defined" if ! defined $option{$_} }
qw( days timezone now config );
my $menu = DynGig::Util::CLI->new
(
'h|help','help menu',
'g|grep=s','pattern',
'c|calendar=s',"calendar mode",
'days=i',"[ $option{days} ] number of days to display",
'timezone=s',"[ $option{timezone} ] timezone",
'now=s',"[ now ] start time",
'config=s',"[ $option{config} ]",
);
Pod::Usage::pod2usage( -input => __FILE__, -output => \*STDERR )
unless Getopt::Long::GetOptions( \%option, $menu->option() );
my $this = bless \%option;
if ( $option{h} )
{
warn join "\n", "Default value in [ ]", $menu->string(), "\n";
}
elsif ( $option{c} )
{
$this->_calendar();
}
else
{
$this->_list();
}
return 0;
}
sub _calendar
{
my $this = shift @_;
return unless $this->{c} =~ /^(\d+)(?:\/+(0?[1-9]|1[0-2]))?$/;
my $pattern = $this->{g};
my $timezone = $this->{timezone};
my %time = ( day => 1, hour => 0, minute => 0, second => 0 );
my $time = DateTime->from_epoch( time_zone => $timezone, epoch => time );
( run in 0.476 second using v1.01-cache-2.11-cpan-5dc5da66d9d )