View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Brent Royal-Gordon > Perl6-Parameters-0.03 > Perl6::Parameters



Annotate this POD (1)

Related Modules



New  2
Open  0
View/Report Bugs
Module Version: 0.03   Source  


Perl6::Parameters – Perl 6-style prototypes with named parameters


        use Perl6::Parameters;

        sub mysub($foo, ARRAY $bar, *%rest) {


Perl6::Parameters is a Perl module which simulates Perl 6's named parameters. (When I talk about "named parameters" I mean something like the parameters you're used to from C, Java and many other languages--not pass-a-hash-with-the-parameters-in-it things.)

Like most other programming languages, Perl 6 will support subroutines with pre-declared variables the parameters are put into. (Using this will be optional, however.) This goes far beyond the "line-noise prototypes" available in Perl 5, which only allow you to control context and automatically take references to some parameters--lines like my($first, $second)=(@_) will no longer be necessary.

Although Perl 6 will have this, Perl 5 doesn't; this module makes it so that Perl 5 does. It uses some other Perl 6-isms too, notably the names for builtin types and the unary-asterisk notation for flattening a list.

Crafting Parameter Lists

Crafting parameter lists is simple; just declare your subroutine and put the parameters separated by commas or semicolons, in parenthesis. (Using a semicolon signifies that all remaining parameters are optional; this may not be available this way in Perl 6, but I'm assuming it is until I hear otherwise.)

Most parameters are just variable names like $foo; however, more sophisticated behavior is possible. There are three ways to achieve this.

The first way is by specifying a type for the variable. Certain types make the actual parameters turn into references to themselves:

For example, if a subroutine had the parameters ($foo, HASH $bar, CODE $baz) and was called with ($scalar, %hash, &mysub) the subroutine would get the contents of $scalar, a reference to %hash and a reference to &mysub.

The second way is by supplying an actual array or hash as a parameter name. This requires an array or hash to be passed in for that parameter; it preserves the length of the array or hash.

The final way is only available for the last parameter: if an array or hash is prefixed with an asterisk, that array or hash will be filled with any additional parameters.



None known--but if you find any, send them to <> and CC <>.


Brent Dax <>


Copyright (C) 2001 Brent Dax.

This module is free software and may be used, redistributed and modified under the same terms as Perl itself.

syntax highlighting: