HTML :: Roles FormHandler vs.Fields

I am using HTML :: FormHandler and try not to repeat a lot of code. I am trying to split a form into as suggested by the HTML :: FormHandler Cookbook . It discusses the possibility of creating custom fields or custom roles to achieve this, however I cannot discern the difference between the two. I understand that they differ from each other in how you implement / use them, but as far as I can tell, they seem to do the same things pretty accurately. My question is, are there situations where there is an explicit choice to use one over the other? Or is it something more preferable? Thanks for the help. I would like to do this right before the code is in production, and harder to change later :)

+3


source to share


1 answer


One option is to use Moose classes so that others use Moose roles.

The concepts are slightly different. Here's a snippet from the Moose Features Guide :

A role encapsulates a piece of behavior or state that can be shared between classes. This is what classes do. It is important to understand that roles are not classes. You cannot inherit from a role, and a role cannot be created. Sometimes we say that roles are consumed either by class or by other role.



Classes allow for inheritance, roles are good if you want to use functions without inheritance.

For a (contrived) example of when you / would not like to use inheritance, see this article on Roles versus inheritance

0


source







All Articles