Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How do I do parametered roles?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Austin Hastings  
View profile  
 More options Apr 30 2004, 5:58 pm
Newsgroups: perl.perl6.language
From: Austin_Hasti...@Yahoo.com (Austin Hastings)
Date: Fri, 30 Apr 2004 17:58:22 -0400
Local: Fri, Apr 30 2004 5:58 pm
Subject: How do I do parametered roles?
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.