Perl6::Parameters

Perl6::Parameters is a module with Perl 6-style prototypes with named parameters.
Download

Perl6::Parameters Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Brent Dax
  • Publisher web site:
  • http://search.cpan.org/~brentdax/Perl6-Interpolators-0.03/Interpolators.pm

Perl6::Parameters Tags


Perl6::Parameters Description

Perl6::Parameters is a module with Perl 6-style prototypes with named parameters. Perl6::Parameters is a module with Perl 6-style prototypes with named parameters.SYNOPSIS use Perl6::Parameters; sub mysub($foo, ARRAY $bar, *%rest) { ... }DETAILSPerl6::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 ListsCrafting 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:ARRAY $foo This turns an array into a reference to itself and stores the reference into $foo.HASH $foo This turns a hash into a reference to itself and stores the reference into $foo.CODE $foo This turns a subroutine into a reference to itself and stores the reference into $foo.SCALAR $foo This turns a scalar into a reference to itself and stores the reference into $foo.GLOB $foo This turns a typeglob into a reference to itself and stores the reference into $foo. Typeglobs will be going away in Perl 6; this type exists in this module so that it's useful for general use in Perl 5.REF $foo This turns any parameter into a reference to itself and stores it into $foo.This only works in Perl 5.8. Otherwise, it's treated the same as any other unrecognized type name.AnythingElse $foo This has no effect in this module; it's treated as though you'd typed $foo without the AnythingElse.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. Requirements: · Perl


Perl6::Parameters Related Software