Subject: | new with no args |
Hi,
I do some pre-processing of the request args and I had a workflow of
$form->new(); $form->add_element(); .. ; $form->populate($processed_args);
But this is broken when no hashref is passed into new. A workaround is to pass in the empty hash.
The documentation for ->new says a $request is necessary but i would expect a warning, an undef, or to default to an empty hash {}.
#--- test-new.t ---
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use_ok 'HTML::TurboForm';
{ # new() - fails as a hashref is required
my $form = HTML::TurboForm->new();
$form->add_element({ type => "Text", name => 'query' });
$form->populate({ query => 'Question' });
is $form->get_value('query'), 'Question', " .. new(), .. get_value('query')";
}
{ # new( {} ) - ok
my $form = HTML::TurboForm->new({}); # a hashref is required
$form->add_element({ type => "Text", name => 'query' });
$form->populate({ query => 'Question' });
is $form->get_value('query'), 'Question', " .. new({}), .. get_value('query')";
}
done_testing;