Perl Weekly Challenge 107: copying myself
One way to let me improve my knowledge about Raku (aka Perl 6) is to implement programs in it. Unluckily, I don’t have any production code to implement in Raku yet (sob!). So, why not try solving the Perl Weekly Challenge tasks?In the following, the assigned tasks for Challenge 107.
Eyes
Yesterday I did a check up of my eyes.In short the situation is immutated, that is a good news at near 6 months from the last surgery. There is nothing to do right now, because it will be a risk for the long term, so the bad news is my sight is not going to imrove.
Quite frankly it is hard for me to be at this sight-level, but I cannot change things, so I think I must get used to.
PWC 107 - Task 1
The first task was a repetition of the second task of Perl Weekly Challenge 43, one of the first challenge I did.I’m not going to repeat the explanation right here, so please check what I wrote in the in the second task of PWC 43
PWC 107 - Task 2
The second task was about a reflection on a class: print out all available methods.This is really simple in Raku, thanks to the Meta Object protocol and the Meta Object Class. The only part, was to remember how to dynamically load an instance given a text name, but thanks to
mortiz
on IRC, I completed the exercise:
sub MAIN( Str $clazz = 'Rat' ) {
.say for ::($clazz).^methods( :local ).sort;
}
The idea is simple:
$clazz
contains the name of the class we want to introspect, and thanks to the ::()
we can get its class. The .^methods
activates the Meta Object and the :local
adverb returns only a list of the methods defined within that class (i.e., not inherited). The other is just printing boilerplate.