Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

lilstevey (4628)

  (email not shown publicly)

  • Heinekin
  • Kro
  • Addlestones
  • Old Rosie
  • Thatchers
  • Strongbow
  • Erdinger
  • Guiness
  • Budvar
  • Leffe ( usually blond )
  • Various Real Ales when in premises suitable

Journal of lilstevey (4628)

Wednesday November 11, 2009
06:44 PM

More perl6 babysteps - finding the methods of a role

[ #39885 ]

Lets start here:

So I code, tentativly....
use v6;

use TestRole;

my $r = TestRole;
say $r;

my @m = $r.methods();

say @m;
role TestRole

   method method1 ( ) { }
   method wildcard ( ) { }
   method randomWWWRRRChars () { }
   method SPLEEEERRRGGGG () { }


C:\ ... \ex6>perl6
Method 'methods' not found for invocant of class ''
in Main (file src\, line 295)

And there lie the daemons... The perl6 ghost docs. Lets try to find something more up to date...

One of the memories of potentially relevant browsing I have is this fella - Jonathan Worthingtons fine work on Signature Introspection And here is a funny thing - anchors are wonderfull, wonderfull things - and delightfully cross discipline. I now recall meta... meta class...

Pause to contemplate. maybe google "rakudo ..." would be a better starting point for future searches.

And back to meta... Apocalypse 12 is about objects and contains some examples:

   MyClass.meta.getmethods() # get the method list of MyClass

It may well be that my rakudo does not yet have the features. Lets get a more recent version.

I start by cloning git:// - and trying to install with the --gen-parrot option - unfortunately as I didn't get around to installing subversion - a visit to should fix that - I end up pumping for Silk Svn - an svn client for windows.

Now I should have tested this before but the signature introspection is now working, unfortunately it looks like meta isn't ( as yet )...

C:\ ... >perl6
Name: $x, Type: Int(), Optional: 0
Name: $y, Type: Str(), Optional: 1

Now lets not give up there - a quick visit of the test suite for perl6 introspection provides an interesting syntax:

@methods = B.^methods(:local);

Lets give that a go... A slight change to is all that is needed.
use v6;

use TestRole;

my $r = TestRole;
say "$r Has the following methods:" ;
my @m = $r.^methods(:local) ;
say join "\n", @m;

And a short perl6 later....

C:\ ... >perl6
TestRole() Has the following methods:

A small, small step. This elephant is going to take a while nibbling at this pace.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • It's nice to see someone familiarize himself with Perl 6. The pitsfalls you encounter give me and others who write books and documentation important clues about how to explain things.

    Also, remember that if you need assistance, there's always #perl6, which is almost always awake, and which practically always has the answers.

    • Many many thanks - the moral support is much appreciatted. I was contemplating dropping it as keeping a commentry takes time away from learning, and also truthfully narrating such is a little like airing ones undies in public, so I'm very greatful for your kind comment.