|
Perl 6
Using Perl 5 Embedding: Revision 8
Perl 5 embedding is enabled by default in Pugs. This allows to you use some Perl 5 modules from Perl 6.
^^ Loading and importing from Perl 5 .pre use perl5:CGI; .pre Currently explict imports work, but implicit ones to not. This works: .pre use perl5:Time::gmtime <gmtime>; say gmtime.mday; .pre ^^ Object-Oriented Classes After loading a Perl5 OO clas, you can use Perl 6 OO notation to call methods on it. See CGI examples below. ^^ Examples of Passing Data to Perl 5 ^^^ Quick Reference | Array | @a | | Array Ref | \@a | | Hash Ref | {...} or \%h | | Hash | %h.kv | | Scalar | 'str' | | Scalar Ref | \$str | ^^^ Strings .pre use perl5:CGI; my $q = CGI.new('a=Hello'); say $q.param('a'); .pre ^^^ Hash references .pre use perl5:CGI; my $q = CGI.new( { a => "Hello" } ); say $q.param('a'); .pre This works too: .pre my %h = ( a => "Hello" ); use perl5:CGI; my $q = CGI.new(\%h); say $q.param('a'); .pre ^^^ Hashes and Named Arguments .pre your_perl5_func(%perl6_hash.kv) .pre Note, Perl 6 does not allow named arguments to start with a dash but Perl 5 does. Here's an example of using it to pass a named argument starting with a dash: .pre use perl5:CGI; my $q = CGI.new; my $cookie = $q.cookie( %( '-name' => 'Hello', value => 'World' ).kv ); print $cookie; .pre ^^ Examples * "cpan-upload.pl"<http://svn.openfoundry.org/pugs/examples/perl5/cpan-upload.pl> is a Perl 6 program that uses several Perl 5 modules * "t/perl5"<http://svn.openfoundry.org/pugs/t/perl5/> is the code in the test suite that tests Perl 5 embedding |