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: 57051
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)

Attachments
HTML-FormHandler-default-values-deflation.patch



Subject: Default values are no longer deflated (regression)
Date: Mon, 26 Apr 2010 16:15:45 -0500
To: bug-HTML-FormHandler [...] rt.cpan.org
From: Andy Clayton <clayton [...] physics.umn.edu>
Download (untitled) / with headers
text/plain 588b
Hello, With 0.31002 (git commit 624848840850c938c3539cbfe7847302bcaefeee) default values are no longer deflated. This seems like a regression as it then requires the default values to be provided in a different format than the actual values (think of using DateTimes, for example). I've provided a patch that updates the test suite and deflates the default value in HTML::FormHandler::Field::_result_from_fields, though I'm not sure if this is the optimum place for a fix. It seems like InitResult.pm may be the best, but that seems to require some additional refactoring. -Andy
diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/Field.pm /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/Field.pm --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/lib/HTML/FormHandler/Field.pm 2010-04-26 15:33:06.769912000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/lib/HTML/FormHandler/Field.pm 2010-04-26 15:59:35.770471000 -0500 @@ -909,10 +909,13 @@ # to initial fields if there is no initial object and no params sub _result_from_fields { my ( $self, $result ) = @_; if ( my @values = $self->get_default_value ) { + if ( $self->_can_deflate ) { + @values = $self->_apply_deflation(@values); + } my $value = @values > 1 ? \@values : shift @values; $self->init_value($value) if defined $value; $result->_set_value($value) if defined $value; } $self->_set_result($result); diff -r -U5 /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/deflate.t /home/admin/clayton/HTML-FormHandler-0.31002/t/deflate.t --- /home/admin/clayton/HTML-FormHandler-0.31002.orig/t/deflate.t 2010-04-26 15:33:08.178150000 -0500 +++ /home/admin/clayton/HTML-FormHandler-0.31002/t/deflate.t 2010-04-26 16:04:26.180794000 -0500 @@ -46,6 +46,32 @@ ok( $form->validated, 'form validated' ); is_deeply( $form->value, { bar => 'aabbcc', foo => 'one-x-two-xx-three-xxx' }, 'right value' ); is( $form->field('foo.one')->fif, 'x', 'correct fif' ); is( $form->field('foo')->value, 'one-x-two-xx-three-xxx', 'right value for foo field' ); +{ + package Test::Deflate; + use HTML::FormHandler::Moose; + extends 'HTML::FormHandler'; + + has_field 'foo' => ( + default => 'deflate me!', + deflation => sub { + my ( $value ) = @_; + + if ( $value eq 'deflate me!' ) { + return 'deflated value'; + } else { + return 'unexpected value'; + } + } + ); + +} + +$form = Test::Deflate->new; +ok( $form, 'form builds' ); + +is( $form->field('foo')->value, 'deflated value', 'default values should be deflated too' ); + + done_testing;
Problem has been fixed.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.