On Tue Oct 04 02:39:44 2005, tony@kasei.com wrote:
Show quoted text> On Thu, Sep 22, 2005 at 04:29:20AM -0400, Guest via RT wrote:
> > Seconded. This bug is still present in 2.42. Attached is a patch against
> > 2.42 to fix it.
>
> It'll be fixed much quicker with a patch to the test file to show the
> problem. Obviously fixing the code isn't the problems. It's making sure
> that this doesn't come back again.
>
> Thanks,
>
> Tony
Attached is a patch, with test (and it also fixes other test cases which
have broken over time).
Though I have to wonder... was it really better to leave this unfixed
for almost 7 years, on the off chance that the problem would "come back
again". Well, I guess if the problem never leaves in the first place, it
can't come back, that's for sure...
diff -ur Class-DBI-AsForm-2.42/lib/Class/DBI/AsForm.pm Class-DBI-AsForm-2.42-ak/lib/Class/DBI/AsForm.pm
--- Class-DBI-AsForm-2.42/lib/Class/DBI/AsForm.pm 2005-09-07 00:24:26.000000000 +0200
+++ Class-DBI-AsForm-2.42-ak/lib/Class/DBI/AsForm.pm 2012-05-13 14:58:33.000000000 +0200
@@ -86,7 +86,7 @@
if ($how and $how =~ /^(text(area|field)|select)$/) {
no strict 'refs';
my $meth = "_to_$how";
- return $class->$meth($field);
+ return $self->$meth($field);
}
my $hasa = $class->__hasa_rels->{$field};
return $self->_to_select($field, $hasa->[0])
diff -ur Class-DBI-AsForm-2.42/t/01.t Class-DBI-AsForm-2.42-ak/t/01.t
--- Class-DBI-AsForm-2.42/t/01.t 2005-09-07 00:22:15.000000000 +0200
+++ Class-DBI-AsForm-2.42-ak/t/01.t 2012-05-13 14:57:50.000000000 +0200
@@ -1,7 +1,7 @@
package Foo;
use Test::More;
eval "require DBD::SQLite" or plan skip_all => "Couldn't load DBD::SQLite";
-plan tests => 4;
+plan tests => 5;
package DBI::Test;
use base 'Class::DBI';
@@ -40,15 +40,20 @@
"Ordinary text field OK");
Foo->has_a(bar => Bar);
-is(Foo->to_field("bar"), "<select name=\"bar\"><option value=1>Hi</option></select>\n",
+is(Foo->to_field("bar"), "<select name=\"bar\"><option value=\"1\">Hi</option></select>\n",
"Select OK");
my $x = bless({id => 1, bar => Bar->retrieve_all(), baz => "Hello there"}, "Foo");
-my %cgi = ( id => '<input name="id" type="text" value=1>
+my %cgi = ( id => '<input name="id" type="text" value="1" />
',
- bar => '<select name="bar"><option selected value=1>Hi</option></select>
+ bar => '<select name="bar"><option selected value="1">Hi</option></select>
',
- baz => '<input name="baz" type="text" value="Hello there">
+ baz => '<input name="baz" type="text" value="Hello there" />
'
);
+
+my %one = ( id => '<input name="id" type="text" value="1" />
+');
+
is_deeply({$x->to_cgi}, \%cgi, "All correct as an object method");
+is_deeply({id => $x->to_field("id", "textfield")}, \%one, "Field with 'how' parameter correct");