Skip to content

Commit

Permalink
Let Timer accept all allowable perl numbers
Browse files Browse the repository at this point in the history
Incidentally, it is now possible to have a timer that never times out using 'inf'
  • Loading branch information
fangly committed Nov 5, 2015
1 parent abce893 commit 1ba2550
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Makefile.PL
Expand Up @@ -27,8 +27,7 @@ TOHERE
## Die nicely in case some install manager cares about the canonical
## error message for this. Not that I've ever seen one, but those
## wacky CPANPLUSers might just do something cool in this case.

## Older perls' Socket.pm don't export IPPROTO_TCP
## Older perls' Socket.pm don't export IPPROTO_TCP
require 5.006;
## Most of the time it's not needed (since IPC::Run tries not to
## use sockets), but the user is not likely to know what the hell
Expand All @@ -39,6 +38,11 @@ TOHERE
}
}

if ( $^V < version->parse('v5.8.1') ) {
# need Scalar::Util::looks_like_number
$PREREQ_PM{'Scalar::List::Utils'} = '1.10';
}

WriteMakefile(
NAME => 'IPC::Run',
ABSTRACT => 'system() and background procs w/ piping, redirs, ptys (Unix, Win32)',
Expand Down
16 changes: 10 additions & 6 deletions lib/IPC/Run/Timer.pm
Expand Up @@ -71,9 +71,9 @@ it's in.
=head2 Time values
All time values are in seconds. Times may be specified as integer or
floating point seconds, optionally preceded by puncuation-separated
days, hours, and minutes.\
All time values are in seconds. Times may be any kind of perl number,
e.g. as integer or floating point seconds, optionally preceded by
punctuation-separated days, hours, and minutes.
Examples:
Expand All @@ -84,6 +84,7 @@ Examples:
1:1 1 minute, 1 second
1:90 2 minutes, 30 seconds
1:2:3:4.5 1 day, 2 hours, 3 minutes, 4.5 seconds
'inf' the infinity perl special number (the timer never finishes)
Absolute date/time strings are *not* accepted: year, month and
day-of-month parsing is not available (patches welcome :-).
Expand Down Expand Up @@ -161,6 +162,7 @@ use Carp;
use Fcntl;
use Symbol;
use Exporter;
use Scalar::Util;
use vars qw( $VERSION @ISA @EXPORT_OK %EXPORT_TAGS );
BEGIN {
$VERSION = '0.90';
Expand Down Expand Up @@ -202,9 +204,11 @@ sub _parse_time {
if (scalar @f > 4) {
croak "IPC::Run: expected <= 4 elements in time string '$_'";
}
map {
$_ =~ /\d+/ ? $_ : croak "IPC::Run: non-numeric element '$_' in time string '$_'";
} @f;
for (@f) {
if (not Scalar::Util::looks_like_number($_)) {
croak "IPC::Run: non-numeric element '$_' in time string '$_'";
}
}
my ( $s, $m, $h, $d ) = reverse @f;
$val = ( (
( $d || 0 ) * 24
Expand Down
4 changes: 3 additions & 1 deletion t/timer.t
Expand Up @@ -19,7 +19,7 @@ BEGIN {
}
}

use Test::More tests => 76;
use Test::More tests => 77;
use IPC::Run qw( run );
use IPC::Run::Timer qw( :all );

Expand All @@ -41,6 +41,8 @@ $t->interval( 30 ); ok( $t->interval >= 30 );
$t->interval( 30.1 ); ok( $t->interval > 30 );
$t->interval( 30.1 ); ok( $t->interval <= 31 );

$t->interval( 'inf' ); ok( $t->interval > 1000 );

$t->interval( "1:0" ); is( $t->interval, 60 );
$t->interval( "1:0:0" ); is( $t->interval, 3600 );
$t->interval( "1:1:1" ); is( $t->interval, 3661 );
Expand Down

0 comments on commit 1ba2550

Please sign in to comment.