perl - Role that modifies or provides a method -


what if want role modify method if consuming class not have it, or provide default method consuming class not?

in 1 case, using method modifier works. in other case, defining ordinary method works. there method works in both cases?

concrete example:

package usualfavorites; use moose::role;  around favorite_things {     ($self, $orig) = @_;     $self->$orig(), qw/doorbells sleighbells/; } 

if consuming class not define favorite_things method, want end favorite_things method returns (doorbells, sleighbells).

just define method in role. if class has method same name method role ignored.

package usualfavorites; use moose::role;  sub favorite_things {     return (); } around favorite_things => sub {     ($orig, $self) = @_;     return ($self->$orig(), qw/doorbells sleighbells/); };  package consumer; use moose; 'usualfavorites';  sub favorite_things {     return qw/shipbells/; } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -