Categories

Posts in this category

Wed, 23 May 2012

News in the Rakudo 2012.05 release


Permanent link

The Rakudo Star release 2012.05 comes with many improvements to the compiler. Some people have asked what they mean, so I want to explain some of them here.

The new -I and -M allow manipulation of the library search path and loading of modules, similar to Perl 5.

perl6 -Ilib t/yourtest.t  # finds your module under lib/

If you want to manipulate the search path from inside a script or module, you can now use the new lib module, again known from Perl 5.

# file t/yourtest.t;
use v6;
use lib 't/lib'; # now can load testing modules from t/lib/Yourmodule/Test.pm
use Yourmodule::Test;
...

If you look at how lib.pm is implemented, you'll notice another new feature: the ability to write a custom EXPORT subroutine -- necessary exactly for things like lib.pm.

But normal exporting and importing is now handled quite well from Rakudo. You can now mark routines as being exported to certain tag names:

module CGI {
    sub h1($text) is export(:HTML) { '<h1>' ~ $text ~ '</h1>' }
    sub param($key) is export { ... };
}

If you want to get only the HTML generating function(s), you can write

use CGI :HTML;

S11 has more details on the exporting and importing mechanism.

You can also import from within a single file by using import instead of use:

module Greeter {
    sub hello($who) is export {
        say "Hello $who";
    }
}

import Greeter; # make sub hello available in the current scope
hello('Perl 6 fans');

[/perl-6] Permanent link