Steve:
The test is in xt/init.t in the repository. It applies a trait to the
field with a 'build_default_over_obj' method. You could also create a
special field type. This would also work with a DBIC row and item => $row.
Maybe it would be better to allow a coderef for that... Hmm....
Gerda
========
use strict;
use warnings;
use Test::More;
{
package My::Default;
use Moose::Role;
sub build_default_over_obj {
return 'From Method';
}
}
{
package My::Other::Form;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
has '+name' => ( default => 'testform_' );
has_field 'optname' => ( temp => 'First' );
has_field 'reqname' => ( required => 1, default_over_obj => 'From
Attribute' );
has_field 'altname' => ( traits => ['My::Default'] );
has_field 'somename';
has_field 'extraname' => ( default_over_obj => '' );
sub default_somename {
my $self = shift;
return 'SN from meth';
}
}
my $init_object = { reqname => 'Starting Perl', optname => 'Over Again',
altname => 'test',
extraname => 'not_empty',
};
my $form = My::Other::Form->new;
ok( $form, 'get form' );
$form->process( init_object => $init_object, params => {} );
is( $form->field('altname')->value, 'From Method', 'correct value' );
Steve:
The test is in xt/init.t in the repository. It applies a trait to the field with a 'build_default_over_obj' method. You could also create a special field type. This would also work with a DBIC row and item => $row.
Maybe it would be better to allow a coderef for that... Hmm....
Gerda