diff -uNr Test-MockRandom-0.99.orig/lib/Test/MockRandom.pm Test-MockRandom-0.99/lib/Test/MockRandom.pm
--- Test-MockRandom-0.99.orig/lib/Test/MockRandom.pm 2006-02-07 04:23:27.000000000 -0800
+++ Test-MockRandom-0.99/lib/Test/MockRandom.pm 2007-12-16 06:09:29.000000000 -0800
@@ -300,7 +300,7 @@
=cut
-sub rand {
+sub rand(;$) {
my ($mult,$val);
if (ref ($_[0]) eq __PACKAGE__) { # we're a MockRandom object
$mult = $_[1];
diff -uNr Test-MockRandom-0.99.orig/t/17-list-context.t Test-MockRandom-0.99/t/17-list-context.t
--- Test-MockRandom-0.99.orig/t/17-list-context.t 1969-12-31 16:00:00.000000000 -0800
+++ Test-MockRandom-0.99/t/17-list-context.t 2007-12-16 06:13:31.000000000 -0800
@@ -0,0 +1,26 @@
+# Test::MockRandom
+use strict;
+
+use Test::More tests => 6 ;
+
+#--------------------------------------------------------------------------#
+# Test package overriding via import to global
+#--------------------------------------------------------------------------#
+
+use Test::MockRandom qw( CORE::GLOBAL );
+use lib qw( . ./t );
+use SomeListPackage;
+
+for ( __PACKAGE__, "SomeListPackage" ) {
+ is( UNIVERSAL::can( $_, 'rand'), undef,
+ "rand should not have been imported into $_" );
+}
+for (qw ( srand oneish )) {
+ can_ok( __PACKAGE__, $_ );
+}
+
+my $obj = SomeListPackage->new;
+isa_ok ( $obj, 'SomeListPackage');
+srand(.5);
+# list_random(10) actually returns 5
+isnt($obj->list_random(10), 0, 'testing $obj->list_random(10) != 0');
diff -uNr Test-MockRandom-0.99.orig/t/SomeListPackage.pm Test-MockRandom-0.99/t/SomeListPackage.pm
--- Test-MockRandom-0.99.orig/t/SomeListPackage.pm 1969-12-31 16:00:00.000000000 -0800
+++ Test-MockRandom-0.99/t/SomeListPackage.pm 2007-12-16 06:11:10.000000000 -0800
@@ -0,0 +1,18 @@
+package SomeListPackage;
+
+sub new {
+ my $class = shift;
+ return bless( {}, ref($class) || $class );
+}
+
+# calls rand() with a list of 0's. in list context, rand() will get 0.
+# but in scalar context, rand() will get $limit.
+sub list_random {
+ my ($self, $limit) = @_;
+ my @list;
+ push(@list, 0) for(1..$limit);
+ my $rnd = rand(@list);
+ return $rnd;
+}
+
+1;
diff -uNr Test-MockRandom-0.99.orig/t/SomeRandPackage.pm Test-MockRandom-0.99/t/SomeRandPackage.pm
--- Test-MockRandom-0.99.orig/t/SomeRandPackage.pm 2006-02-07 04:23:27.000000000 -0800
+++ Test-MockRandom-0.99/t/SomeRandPackage.pm 2007-12-16 06:12:24.000000000 -0800
@@ -5,7 +5,7 @@
return bless( {}, ref($class) || $class );
}
-sub rand {
+sub rand(;$) {
my $rnd = CORE::rand;
return $rnd;
}