Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the HTML-FormHandler CPAN distribution.

Report information
The Basics
Id: 56951
Status: resolved
Priority: 0/
Queue: HTML-FormHandler

People
Owner: Nobody in particular
Requestors: clayton [...] physics.umn.edu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Defaults override actual item values
Date: Mon, 26 Apr 2010 14:47:21 -0500
To: bug-HTML-FormHandler [...] rt.cpan.org
From: Andy Clayton <clayton [...] physics.umn.edu>
Hello, I'm having trouble with FormHandler 0.31002 where default values override/have higher precedence than the actual values. I've attached a patch that updates the test suite to illustrate the issue as well as provides a fix. Thanks, Andy
Index: BuildFields.pm =================================================================== --- BuildFields.pm (revision 1431) +++ BuildFields.pm (revision 1432) @@ -201,10 +201,11 @@ my $loaded; foreach my $ns (@{$self->field_name_space}) { $class = $ns . "::" . $type; - if( Class::MOP::load_class($class) ) { + try { + Class::MOP::load_class($class); $loaded++; last; - } + } catch { } } die "Could not load field class '$type' for field '$name'" unless $loaded;
The patch that I see does not have a testcase and is not against the current level of code. Was the wrong file uploaded?
Subject: Re: [rt.cpan.org #56951] Defaults override actual item values
Date: Fri, 30 Apr 2010 11:23:01 -0500
To: bug-HTML-FormHandler [...] rt.cpan.org
From: Andy Clayton <clayton [...] physics.umn.edu>
Oops, you're right. This one should make more sense. Gerda Shank via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=56951 > > > The patch that I see does not have a testcase and is not against the > current level of code. Was the wrong file uploaded? >
diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/InitResult.pm /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/InitResult.pm --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/InitResult.pm 2010-04-21 19:39:22.000000000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/InitResult.pm 2010-04-26 14:42:56.998197000 -0500 @@ -100,18 +100,18 @@ sub _get_value { my ( $self, $field, $item ) = @_; my $accessor = $field->accessor; my @values; - if ( @values = $field->get_default_value ) { - } - elsif ( blessed($item) && $item->can($accessor) ) { + if ( blessed($item) && $item->can($accessor) ) { @values = $item->$accessor; } elsif ( exists $item->{$accessor} ) { @values = $item->{$accessor}; } + elsif ( @values = $field->get_default_value ) { + } else { return; } if( $field->_can_deflate ) { @values = $field->_apply_deflation(@values); diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/defaults.t /home/admin/clayton/HTML-FormHandler-0.31002/t/defaults.t --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/defaults.t 2010-04-21 19:39:22.000000000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/t/defaults.t 2010-04-26 14:43:44.910531000 -0500 @@ -100,6 +100,26 @@ } $form = Test::Form->new; is( $form->field('foo')->value, 'some_quux', 'field initialized by init_object' ); +{ + package Mock::Object; + use Moose; + has 'meow' => ( is => 'rw' ); +} +{ + package Test::Object; + use HTML::FormHandler::Moose; + extends 'HTML::FormHandler'; + with 'HTML::FormHandler::Model::Object'; + has_field 'meow' => ( default => 'this_should_get_overriden' ); + +} + +my $obj2 = Mock::Object->new( meow => 'the_real_meow' ); + +$form2 = Test::Object->new; +$form2->process( item => $obj2, item_id => 1, params => {} ); +is( $form2->field('meow')->value, 'the_real_meow', 'defaults should not override actual item values'); + done_testing;
Subject: Re: [rt.cpan.org #56951] Defaults override actual item values
Date: Fri, 30 Apr 2010 11:27:52 -0500
To: bug-HTML-FormHandler [...] rt.cpan.org
From: Andy Clayton <clayton [...] physics.umn.edu>
Sorry, I should have looked over this one last time. The other one worked, but here's an updated patch with a spelling fix and some cleanup of variable weirdness in the test...
diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/InitResult.pm /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/InitResult.pm --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/InitResult.pm 2010-04-21 19:39:22.000000000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/InitResult.pm 2010-04-26 14:42:56.998197000 -0500 @@ -100,18 +100,18 @@ sub _get_value { my ( $self, $field, $item ) = @_; my $accessor = $field->accessor; my @values; - if ( @values = $field->get_default_value ) { - } - elsif ( blessed($item) && $item->can($accessor) ) { + if ( blessed($item) && $item->can($accessor) ) { @values = $item->$accessor; } elsif ( exists $item->{$accessor} ) { @values = $item->{$accessor}; } + elsif ( @values = $field->get_default_value ) { + } else { return; } if( $field->_can_deflate ) { @values = $field->_apply_deflation(@values); diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/defaults.t /home/admin/clayton/HTML-FormHandler-0.31002/t/defaults.t --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/defaults.t 2010-04-21 19:39:22.000000000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/t/defaults.t 2010-04-26 14:43:44.910531000 -0500 @@ -100,6 +100,26 @@ } $form = Test::Form->new; is( $form->field('foo')->value, 'some_quux', 'field initialized by init_object' ); +{ + package Mock::Object; + use Moose; + has 'meow' => ( is => 'rw' ); +} +{ + package Test::Object; + use HTML::FormHandler::Moose; + extends 'HTML::FormHandler'; + with 'HTML::FormHandler::Model::Object'; + has_field 'meow' => ( default => 'this_should_get_overridden' ); + +} + +$obj = Mock::Object->new( meow => 'the_real_meow' ); + +$form = Test::Object->new; +$form->process( item => $obj, item_id => 1, params => {} ); +is( $form->field('meow')->value, 'the_real_meow', 'defaults should not override actual item values'); + done_testing;
Flipped the defaults-override-item switch. Now defaults that you want to override an initial item/init_object, you can use 'default_over_obj' or put the defaults into your item/init_object.