Perl6 modules in Rakudo baby-steps, part 1
Here is an example of what a module can look like. In this case it only has a simple method that greets the user:
class Greeter;method greet($name = 'world') {
say "hello $name";
}
Now to use the module we can write something like:
BEGIN { @*INC.push('Greeter/lib') }use Greeter;
my $x = Greeter.new;
$x.greet('rakudo');
The only tricky part is actually the push in the BEGIN block, to add your lib directory. Of course running this is as simple as:
$ ./perl6 greeter.p6 hello rakudo
For the record, you can also use the PERL6LIB environment variable on the outside of the program, just like PERL5LIB in p5.
I know this might be a bit far fetching - but for translating my WebNano web framework to Perl6 I would need a way to do the following:
I know I am confusing here module and class - and that both nouns have different meaning in Perl6 - but I hope my intent is clear. How would you translate that to Perl6?
Hmm - sorry. I now see that my question comes out as a rude 'do it for me' demand. Please don't look at it like that - it was just the first thing I was thinking about when reading your post. Now I think it could be better formulated as following questions:
Cheers.
Z.