Subject: | $obj->spawn doesn't work |
When used on an existing Object::Enum object, spawn returns a new object blessed into
package undef instead of the proper class.
I've tested with Object-Enum-0.070 and perl 5.8.8 on Gentoo Linux.
The following patch fixes the problem, and includes a test case:
diff -rNu Object-Enum-0.070/lib/Object/Enum.pm Object-Enum-0.070.mod/lib/Object/
Enum.pm
--- Object-Enum-0.070/lib/Object/Enum.pm 2006-08-28 17:36:21.000000000 -0400
+++ Object-Enum-0.070.mod/lib/Object/Enum.pm 2007-05-25 00:20:26.000000000
-0400
@@ -185,7 +185,7 @@
my $class = shift;
return bless {
value => $class->_default,
- } => $class;
+ } => (ref $class or $class);
}
=head2 value
diff -rNu Object-Enum-0.070/t/regression.t Object-Enum-0.070.mod/t/regression.t
--- Object-Enum-0.070/t/regression.t 2006-08-28 17:14:50.000000000 -0400
+++ Object-Enum-0.070.mod/t/regression.t 2007-05-25 00:22:11.000000000 -0400
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 1;
+use Test::More tests => 2;
use Object::Enum (
Enum => { -as => 'foo', values => ['a', 'b'] },
@@ -16,3 +16,8 @@
foo();
is($warn, undef, "no redefine warning");
}
+
+{
+ my $obj = new Object::Enum(['foo']);
+ ok(eval { $obj->spawn->set_foo->is_foo }, "spawn works on objects");
+}