AnyEvent-Timer-Cron
view release on metacpan or search on metacpan
{
"abstract" : "cron based timers for AnyEvent",
"author" : [
"haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>"
],
"dynamic_config" : 0,
"generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'cron based timers for AnyEvent'
author:
- 'haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>'
build_requires:
Test::More: '0.94'
dynamic_config: 0
generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
NAME
AnyEvent::Timer::Cron - cron based timers for AnyEvent
SYNOPSIS
use AnyEvent;
use AnyEvent::Timer::Cron;
my $w; $w = AnyEvent::Timer::Cron->new(cron => '0 1 * * *', cb => sub {
undef $w;
...
});
AnyEvent->condvar->recv;
DESCRIPTION
This module creates timers based on cron rules.
This module primarily exists to replace similar that try to do too much
work, instead providing the simplest implementation, and using
AnyEvent's standard conventions for timer lifetime.
METHODS
new( cron => $cron, cb => sub {} )
Creates a new cron timer. The callback will be called continually
according to the cron rules until the object is destroyed.
cron
Required. A cron rule, either in string form or as a
DateTime::Event::Cron, DateTime::Event::Cron::Quartz, or
DateTime::Set object.
cb Required. The callback to call for the cron events.
time_zone
lib/AnyEvent/Timer/Cron.pm view on Meta::CPAN
}
if ($cron->$_can('next')) {
return sub { $cron->next(@_) };
}
elsif ($cron->$_can('get_next_valid_time_after')) {
return sub { $cron->get_next_valid_time_after(@_) };
}
die "Invalid cron!";
},
);
has '_timer' => (is => 'rw');
sub BUILD {
my $self = shift;
$self->create_timer;
}
sub create_timer {
my $self = shift;
weaken $self;
my $now = DateTime->from_epoch(epoch => AnyEvent->now);
$now->set_time_zone( $self->time_zone ) if $self->time_zone;
my $next = $self->next_event($now);
return
if not $next;
my $interval = $next->subtract_datetime_absolute($now)->in_units('nanoseconds') / 1_000_000_000;
$self->_timer(AnyEvent->timer(
after => $interval,
cb => sub {
$self->{cb}->();
$self && $self->create_timer;
},
));
}
sub next_event {
my $self = shift;
my $now = shift || DateTime->from_epoch(epoch => AnyEvent->now);
$now->set_time_zone( $self->time_zone ) if $self->time_zone;
$self->_cron->($now);
}
1;
__END__
=head1 NAME
AnyEvent::Timer::Cron - cron based timers for AnyEvent
=head1 SYNOPSIS
use AnyEvent;
use AnyEvent::Timer::Cron;
my $w; $w = AnyEvent::Timer::Cron->new(cron => '0 1 * * *', cb => sub {
undef $w;
...
});
AnyEvent->condvar->recv;
=head1 DESCRIPTION
This module creates timers based on cron rules.
This module primarily exists to replace similar that try to do too
much work, instead providing the simplest implementation, and using
AnyEvent's standard conventions for timer lifetime.
=head1 METHODS
=head2 new( cron => $cron, cb => sub {} )
Creates a new cron timer. The callback will be called continually
according to the cron rules until the object is destroyed.
=over 4
=item cron
Required. A cron rule, either in string form or as a
L<DateTime::Event::Cron>, L<DateTime::Event::Cron::Quartz>, or
L<DateTime::Set> object.
( run in 0.611 second using v1.01-cache-2.11-cpan-49f99fa48dc )