| 1 | package AnyEvent::Timer::Cron; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.002000'; | |||||||||||||||||||
| 5 | 1 | $VERSION = eval $VERSION; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use AnyEvent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Safe::Isa; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use DateTime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use DateTime::Event::Cron; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | has 'cb' => (is => 'ro', required => 1); | |||||||||||||||||||
| 15 | 1 | has 'time_zone' => (is => 'ro'); | |||||||||||||||||||
| 16 | has '_cron' => ( | ||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||
| 19 | init_arg => 'cron', | ||||||||||||||||||||
| 20 | 0 | ▶ | coerce => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 21 | 0 | my $cron = shift; | |||||||||||||||||||
| 22 | 0 | ▶ | if (!ref $cron) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 0 | $cron = DateTime::Event::Cron->new($cron); | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | 0 | ▶ | if ($cron->$_can('next')) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 26 | 0 | ▶ | return sub { $cron->next(@_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | elsif ($cron->$_can('get_next_valid_time_after')) { | ||||||||||||||||||||
| 29 | 0 | ▶ | return sub { $cron->get_next_valid_time_after(@_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 0 | die "Invalid cron!"; | |||||||||||||||||||
| 32 | }, | ||||||||||||||||||||
| 33 | 1 | ); | |||||||||||||||||||
| 34 | 1 | has '_timer' => (is => 'rw'); | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub BUILD { | ||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||
| 38 | 0 | $self->create_timer; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub create_timer { | ||||||||||||||||||
|
Subroutine
create_timer: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||
| 43 | 0 | weaken $self; | |||||||||||||||||||
| 44 | 0 | my $now = DateTime->from_epoch(epoch => AnyEvent->now); | |||||||||||||||||||
| 45 | 0 | ▶ | $now->set_time_zone( $self->time_zone ) if $self->time_zone; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | my $next = $self->next_event($now); | |||||||||||||||||||
| 47 | return | ||||||||||||||||||||
| 48 | 0 | ▶ | if not $next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | my $interval = $next->subtract_datetime_absolute($now)->in_units('nanoseconds') / 1_000_000_000; | |||||||||||||||||||
| 50 | $self->_timer(AnyEvent->timer( | ||||||||||||||||||||
| 51 | after => $interval, | ||||||||||||||||||||
| 52 | 0 | ▶ | cb => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 53 | 0 | $self->{cb}->(); | |||||||||||||||||||
| 54 | 0 | ▶ | $self && $self->create_timer; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||
| 56 | 0 | )); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | sub next_event { | ||||||||||||||||||
|
Subroutine
next_event: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||
| 61 | 0 | ▶ | my $now = shift || DateTime->from_epoch(epoch => AnyEvent->now); | ||||||||||||||||||
|
Condition0%0/3
shift() || 'DateTime'->from_epoch('epoch', 'AnyEvent'->now)
MC/DC0%0/2
shift() || 'DateTime'->from_epoch('epoch', 'AnyEvent'->now)
shift()
'DateTime'->from_epoch('epoch', 'AnyEvent'->now)
Truth table0%0/3
A || B
A= shift()B= 'DateTime'->from_epoch('epoch', 'AnyEvent'->now)
| |||||||||||||||||||||
| 62 | 0 | ▶ | $now->set_time_zone( $self->time_zone ) if $self->time_zone; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | $self->_cron->($now); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||||