--- Larry Wall <[EMAIL PROTECTED]> wrote:
> Well, it's not nearly as general as we're making it, but the
> inspiration for it comes in part from the "Traits" paper:
> 
>     http://www.cse.ogi.edu/~black/publications/TR_CSE_02-012.pdf
> 
> Basically, I'm attempting to take their concept and unify it with
> properties, interfaces, generics, aspects, and mixins.  Among other
> things...

Ok, having read this now (at least corsorily) and compared it with what I
believe I understand about the way P6 is implementing
traits/properties/roles, I begin to get it, and I am, as usual, suitably
impressed and excited. 

So is this a good time to divert this topic into an elaboration of roles?

> : Somebody drop me an example?
>
> Well, it hasn't been defined yet.  Likely there will be some syntax
>
>   my property foo;
>
> that is shorthand for something vaguely resembling
>
>   my role foo is property {
>      has $.foo is rw;
>   }

So if I want to implement a package of related roles that I commonly use in
our In-House code, such as to specify how verbose an object should be on log
output, and how touchy it should be over whether a problem is screamingly
fatal or just warningly annoying, and maybe toss in a shorthand method that
lets me pass the names of some specific traits I want to be able to use (
like "allow(qw/winkin blinkin nod/)" or some such), it should be pretty
simple....but I'm having a hard time coming up with the syntax that declares
the package and exports the roles. 

  module IHL::Roles;
  @ISA = 'Exporter';
  @EXPORT_OK = qw/ fatal verbose allow setvals /;

  our role fatal is property {
      has $.fatal is rw;
  }

  our role verbose is property {
      has $.verbose is rw;
  }

  sub allow {
      .... # I'd want to make this one too complex to actually do it here
  }

  sub import {
      allow @_[1...];
  }

  sub setvals ($o, [EMAIL PROTECTED]) {
      "\$o.$_ = true".eval for @t; # surely there's a better way to do this?
  }

then write allow() to build roles for each value passed in, maybe taking an
arg to say whether they should be truly global, or built in the caller's
namespace.... 
Then I could say

  use IHL::Roles qw/ allow setvals fatal verbose /;
  use Foo;
  my $o = Foo.new();
  allow qw/ foo bar baz /;
  setvals($o,qw/ verbose baz /);  

I'm trying to make sure I don't tumble back into pure P5 here, but I don't
think I'm really awake yet. :) 





*****
"The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential, proprietary, and/or
privileged material.  Any review, retransmission, dissemination or other use
of, or taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.  If you received
this in error, please contact the sender and delete the material from all
computers.60"

Reply via email to