[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl6-language
Subject:    Mixing in to method objects
From:       Matthew Walton <matthew () matthew-walton ! co ! uk>
Date:       2009-06-25 19:59:02
Message-ID: d61bb5bc0906251259v125f1963s19358fbd0c392c2c () mail ! gmail ! com
[Download RAW message or body]

As I understand it, in Perl 6 a method of a class, as indeed all
similar things like a sub or a regex, is represented by an object. If
it's an object, I should be able to mix a role into it, right?
Something like:

role Fancy {
  has $.something is rw;
}

sub a {  }

&a does Fancy;
&a.something = 56;
say &a.something;
a();

And so forth. Now, Rakudo's got a whole load of bugs I'm tripping over
trying to do things like this, but I thought I'd check to see if it's
supposed to be possible, and if it isn't, why not.

Also syntactically, is there or should there be a way to do it which
doesn't involve having to haul out the &a afterwards - so can the
'does' or maybe a 'but' be attached to the definition itself?

As for why I want to do this, I've got something in mind which would
be potentially much nicer if some methods can carry a load of extra
data around with them - which seems like an excellent use for a mixin,
especially as I could then smartmatch against it in order to pick out
the relevant methods from the .^methods list.

Matthew

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic