Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the most efficient way to override an attribute in lots of my Moose based sub classes?
    primarykey
    data
    text
    <p>I am using <a href="http://search.cpan.org/perldoc/HTML::FormHandler" rel="nofollow noreferrer">HTML::FormHandler</a>. To use it one is supposed to subclass from it and then you can override some attributes such as <code>field_name_space</code> or <code>attribute_name_space</code>. </p> <p>However, I now have lots of forms all extending <code>HTML::FormHandler</code> or its DBIC based variant <a href="http://search.cpan.org/perldoc/HTML::FormHandler::Model::DBIC" rel="nofollow noreferrer">HTML::FormHandler::Model::DBIC</a> and therefore have these overidden attributes repeated many times.</p> <p>I tried to put them in a role but get an error that <code>+attr</code> notation is not supported in Roles. Fair enough.</p> <p>What is the best way of eliminating this repetition? I thought perhaps subclassing but then I would have to do it twice for <code>HTML::FormHandler</code> and <code>HTML::FormHandler::Model::DBIC</code>, plus I believe general thought was that subclassing is generally better achieved with Roles instead.</p> <p><strong>Update:</strong> I thought it would be a good idea to give an example. This is what I am currently doing - and it involves code repetition. As you can see one form uses a different parent class so I cannot create one parent class to put the attribute overrides in. I would have to create two - and that also adds redundancy. </p> <pre><code>package MyApp::Form::Foo; # this form does not interface with DBIC extends 'HTML::Formhandler'; has '+html_prefix' =&gt; (default =&gt; 1); has '+field_traits' =&gt; (default =&gt; sub { ['MyApp::Form::Trait::Field'] }); has '+field_name_space' =&gt; (default =&gt; 'MyApp::Form::Field'); has '+widget_name_space' =&gt; (default =&gt; sub { ['MyApp::Form::Widget'] }); has '+widget_wrapper' =&gt; (default =&gt; 'None'); ... package MyApp::Form::Bar; # this form uses a DBIC object extends 'HTML::Formhandler::Model::DBIC'; has '+html_prefix' =&gt; (default =&gt; 1); has '+field_traits' =&gt; (default =&gt; sub { ['MyApp::Form::Trait::Field'] }); has '+field_name_space' =&gt; (default =&gt; 'MyApp::Form::Field'); has '+widget_name_space' =&gt; (default =&gt; sub { ['MyApp::Form::Widget'] }); has '+widget_wrapper' =&gt; (default =&gt; 'None'); ... package MyApp::Form::Baz; # this form also uses a DBIC object extends 'HTML::Formhandler::Model::DBIC'; has '+html_prefix' =&gt; (default =&gt; 1); has '+field_traits' =&gt; (default =&gt; sub { ['MyApp::Form::Trait::Field'] }); has '+field_name_space' =&gt; (default =&gt; 'MyApp::Form::Field'); has '+widget_name_space' =&gt; (default =&gt; sub { ['MyApp::Form::Widget'] }); has '+widget_wrapper' =&gt; (default =&gt; 'None'); ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload