Suppose that I have, for example:
class Session {
has @:messages;
method clear_messages() {...}
method add_message($msg) {...}
method have_messages() {...}
method get_messages() returns Array {... font color="black" ...}
}
And suppose I add to it:
class Session {
has @:messages;
method clear_messages() {...}
method add_message($msg) {...}
method have_messages() {...}
method get_messages() returns Array {... font color="black" ...}
has @:errors;
method clear_errors() {...}
method add_error($msg) {...}
method have_errors() {...}
method get_errors() returns Array {... font color="red" ...}
}
So I realize that not only is the whole list-of-messages thing a packageable
behavior (read: Role or Class) but that this particular behavior recurs
within my class.
One solution is to compose member objects that implement this behavior:
if ($my_object.messages.have_messages) {...}
But that sucks.
What I want to do is to say:
1- There's a "list of generic messages" role.
2- The ListOfMessages defines an attribute.
3- The ListOfMessages needs some sort of customizable behavior.
And then implement two different parameterized invocations of the same role
(MetaRole?)
class Session
{
does ListOfMessages
(
attribute_base => 'messages',
method_base => 'messages',
display_color => 'black'
);
does ListOfMessages
(
attribute_base => 'errors',
method_base => 'errors',
display_color => 'red'
);
...
}
(Classes are described as "parameterless subroutines". I'd like a
parameterful one.)
Can I just do:
role ListOfMessages($attribute_base, $method_base, $display_color) {...}
or what?
=Austin