From: Vincent Pit Date: Tue, 5 Aug 2008 10:27:06 +0000 (+0200) Subject: stat() can also return no arguments if the file can't be found. Hopefully, our %ops... X-Git-Tag: v0.02~8 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Nary.git;a=commitdiff_plain;h=2d8aec84852aa584b41d7cfce42088fec7ca8582 stat() can also return no arguments if the file can't be found. Hopefully, our %ops hash can also hold probabilities of return. Make sure that it's duplicated when returned --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index c7792d5..4a02bc2 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -204,7 +204,7 @@ $ops{$_} = 1 for qw/padsv/; $ops{$_} = 'list' for qw/padav/; $ops{$_} = 'list' for qw/padhv rv2hv/; $ops{$_} = 'list' for qw/padany flip match entereval readline/; -$ops{stat} = 13; +$ops{stat} = { 0 => 0.5, 13 => 0.5 }; $ops{caller} = sub { my @a = caller 0; scalar @a }->(); $ops{localtime} = do { my @a = localtime; scalar @a }; $ops{gmtime} = do { my @a = gmtime; scalar @a }; @@ -255,7 +255,11 @@ sub expect_list { my $n = name($op); my $meth = $self->can('pp_' . $n); return $self->$meth($op) if $meth; - return $ops{$n} => 0 if exists $ops{$n}; + if (exists $ops{$n}) { + my $r = $ops{$n}; + $r = { %$r } if ref $r eq 'HASH'; + return $r => 0; + } if ($op->flags & OPf_KIDS) { my @res = (0); diff --git a/t/20-return.t b/t/20-return.t index c4194a6..b47babb 100644 --- a/t/20-return.t +++ b/t/20-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 54; +use Test::More tests => 53; use Sub::Nary; @@ -75,7 +75,6 @@ my @tests = ( [ sub { return -f $0, -r $0 }, 2 ], - [ sub { return stat $0 }, 13 ], [ sub { return caller 0 }, sub { my @a = caller 0; scalar @a }->() ], [ sub { return localtime }, do { my @a = localtime; scalar @a } ], [ sub { return gmtime }, do { my @a = gmtime; scalar @a } ], diff --git a/t/21-list.t b/t/21-list.t index 80eb5ab..4f97358 100644 --- a/t/21-list.t +++ b/t/21-list.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 40; +use Test::More tests => 39; use Sub::Nary; @@ -63,7 +63,6 @@ my @tests = ( [ sub { -f $0, -r $0 }, 2 ], - [ sub { stat $0 }, 13 ], [ sub { caller 0 }, sub { my @a = caller 0; scalar @a }->() ], [ sub { localtime }, do { my @a = localtime; scalar @a } ], [ sub { gmtime }, do { my @a = gmtime; scalar @a } ], diff --git a/t/23-branch.t b/t/23-branch.t index cfc87c2..914b975 100644 --- a/t/23-branch.t +++ b/t/23-branch.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 15; +use Test::More tests => 16; use Sub::Nary; @@ -60,7 +60,8 @@ my @tests = ( [ \&retinif, { 2 => 1 } ], - [ sub { <*.*> }, { list => 1 / 3, 1 => 2 / 3 } ], + [ sub { <*.*> }, { list => 1 / 3, 1 => 2 / 3 } ], + [ sub { stat $0 }, { 0 => 0.5, 13 => 0.5 } ], ); my $i = 1;