X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FScheduler.pm;fp=lib%2FCatalyst%2FPlugin%2FScheduler.pm;h=ab4073354fef92071352250a525df966bc5abffb;hb=4796c217de7c79f97dbbe87bf6fec327d1e4d790;hp=90c086044d95d3c90d2ac51234c59461e680ef08;hpb=ea66b1c7ee09e900864e5fa122addafe184d3660;p=catagits%2FCatalyst-Plugin-Scheduler.git diff --git a/lib/Catalyst/Plugin/Scheduler.pm b/lib/Catalyst/Plugin/Scheduler.pm index 90c0860..ab40733 100644 --- a/lib/Catalyst/Plugin/Scheduler.pm +++ b/lib/Catalyst/Plugin/Scheduler.pm @@ -12,7 +12,7 @@ use Set::Scalar; use Storable qw/lock_store lock_retrieve/; use YAML; -our $VERSION = '0.04'; +our $VERSION = '0.05'; __PACKAGE__->mk_classdata( '_events' => [] ); __PACKAGE__->mk_accessors('_event_state'); @@ -26,7 +26,7 @@ sub schedule { } my $conf = $class->config->{scheduler}; - + my $event = { trigger => $args{trigger}, event => $args{event}, @@ -37,7 +37,7 @@ sub schedule { # replace keywords that Set::Crontab doesn't support $args{at} = _prepare_cron( $args{at} ); - + # parse the cron entry into a DateTime::Set my $set; eval { $set = DateTime::Event::Cron->from_cron( $args{at} ) }; @@ -220,7 +220,7 @@ sub _check_yaml { $c->_events( [] ); my $yaml = YAML::LoadFile( $c->config->{scheduler}->{yaml_file} ); - + foreach my $event ( @{$yaml} ) { $c->schedule( %{$event} ); } @@ -353,7 +353,9 @@ sub _prepare_cron { thu => 4, fri => 5, sat => 6, - + ); + + my %replace_at = ( 'yearly' => '0 0 1 1 *', 'annually' => '0 0 1 1 *', 'monthly' => '0 0 1 * *', @@ -362,20 +364,17 @@ sub _prepare_cron { 'midnight' => '0 0 * * *', 'hourly' => '0 * * * *', ); + + if ( $cron =~ /^\@/ ) { + $cron =~ s/^\@//; + return $replace_at{ $cron }; + } for my $name ( keys %replace ) { my $value = $replace{$name}; - - if ( $cron =~ /^\@$name/ ) { - $cron = $value; - last; - } - else { - $cron =~ s/$name/$value/i; - last unless $cron =~ /\w/; - } + $cron =~ s/$name/$value/i; + last unless $cron =~ /\w/; } - return $cron; }