From f035722d940d2aba3304491d0f669a35df0628c3 Mon Sep 17 00:00:00 2001 From: "Michael G. Schwern" Date: Fri, 25 Nov 2011 14:10:48 -0800 Subject: [PATCH] Add the value to the incorrect argument message. That will help users debug their problem. For #149 --- lib/perl5i/2/ARRAY.pm | 4 ++-- t/popn.t | 4 ++-- t/shiftn.t | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/perl5i/2/ARRAY.pm b/lib/perl5i/2/ARRAY.pm index b5af465..30a4c93 100644 --- a/lib/perl5i/2/ARRAY.pm +++ b/lib/perl5i/2/ARRAY.pm @@ -58,7 +58,7 @@ method grep($filter) { method popn($times) { Carp::croak("popn() takes the number of elements to pop") unless defined $times; - Carp::croak("popn() takes a positive integer or zero") + Carp::croak("popn() takes a positive integer or zero, not '$times'") unless $times->is_integer && ($times->is_positive or $times == 0); # splice() will choke if you walk off the array, so rein it in @@ -71,7 +71,7 @@ method popn($times) { method shiftn($times) { Carp::croak("shiftn() takes the number of elements to shift") unless defined $times; - Carp::croak("shiftn() takes a positive integer or zero") + Carp::croak("shiftn() takes a positive integer or zero, not '$times'") unless $times->is_integer && ($times->is_positive or $times == 0); # splice() will choke if you walk off the array, so rein it in diff --git a/t/popn.t b/t/popn.t index ef77bd6..c85a4f5 100644 --- a/t/popn.t +++ b/t/popn.t @@ -14,13 +14,13 @@ note "popn with no args"; { note "popn with negative arg"; { my @array = (1, 2, 3); throws_ok { @array->popn(-20); } - qr{^\Qpopn() takes a positive integer or zero at $0 line }; + qr{^\Qpopn() takes a positive integer or zero, not '-20' at $0 line }; } note "popn with non-numerical argument"; { my @array = (1, 2, 3); throws_ok { @array->popn("rawr"); } - qr{^\Qpopn() takes a positive integer or zero at $0 line }; + qr{^\Qpopn() takes a positive integer or zero, not 'rawr' at $0 line }; } note "popn with arg == 0"; { diff --git a/t/shiftn.t b/t/shiftn.t index 2a7202d..311b68f 100644 --- a/t/shiftn.t +++ b/t/shiftn.t @@ -14,13 +14,13 @@ note "shiftn with no args"; { note "shiftn with negative arg"; { my @array = (1, 2, 3); throws_ok { @array->shiftn(-20); } - qr{^\Qshiftn() takes a positive integer or zero at $0 line }; + qr{^\Qshiftn() takes a positive integer or zero, not '-20' at $0 line }; } note "shiftn with non-numerical argument"; { my @array = (1, 2, 3); throws_ok { @array->shiftn("meow"); } - qr{^\Qshiftn() takes a positive integer or zero at $0 line }; + qr{^\Qshiftn() takes a positive integer or zero, not 'meow' at $0 line }; } note "shiftn with arg == 0"; {