Stories
Slash Boxes
Comments
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)

lilstevey
  (email not shown publicly)

Consumes:
  • 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:

http://dev.perl.org/perl6/rfc/335.html

So I code, tentativly....

test.pl
use v6;

use TestRole;

my $r = TestRole;
say $r;

my @m = $r.methods();

say @m;
TestRole.pm
role TestRole
{

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

Results:

C:\ ... \ex6>perl6 test.pl
TestRole()
Method 'methods' not found for invocant of class ''
in Main (file src\gen_setting.pm, 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://github.com/rakudo/rakudo.git - and trying to install with the --gen-parrot option - unfortunately as I didn't get around to installing subversion - a visit to http://subversion.tigris.org/ 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 testsig.pl
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 test.pl is all that is needed.

test.pl
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 test.pl later....

C:\ ... >perl6 test.pl
TestRole() Has the following methods:
method1
wildcard
randomWWWRRRChars
SPLEEEERRRGGGG

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.
 Full
 Abbreviated
 Hidden
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.