The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

twigils - Perl 6 style twigils for Perl 5

SYNOPSIS

    use twigils;

    intro_twigil_my_var $!foo;

    $!foo = 42;

    say $!foo;

DESCRIPTION

This module implements Perl 6 style twigils for Perl 5.

Twigils are similar to Perl's sigils ($, @, and %, most importantly), but consist of two characters. This module doesn't give any particular meaning to any twigils and leaves that as the user's responsibility.

FUNCTIONS

intro_twigil_my_var $varname

  intro_twigil_my_var $!foo;

Introduces a new lexical twigil variable. Similar to perl's built-in my keyword.

intro_twigil_state_var $varname

  intro_twigil_state_var $!foo;

Introduces a new lexical twigil state variable. Similar to perl's built-in state keyword.

intro_twigil_our_var $varname

  intro_twigil_our_var $!foo;

Introduces a new lexical twigil variable as an alias to a package variable. Similar to perl's built-in our keyword.

WARNING

This is a ALPHA release made mostly to make it easier for the p5-mop project to experiment with using twigils. I don't recommend anyone using this module for production code. See also: "CAVEATS".

CAVEATS

  • Special punctuation variables and alphanumeric infix operators

    Code such as $.eq 42 would normally be interpreted as comparing the contents of the special variable $. with the constant 42 using the eq infix operator. However, in the presence of a twigil variable who's name consists of a special variable name followed by the name of an infix operator (e.g. $.eq) an expression like $.eq 42 will be interpreted as a lookup of the variable $.eq followed by a constant 42, which will result in a syntax error. To disambiguate between these two possible interpretations, use extra whitespace between the special variable and the infix operator, i.e. $. eq 42.

  • Spaces between twigil and the variable identifier are forbidden

    As a consequence of the above caveat, it's not possible to use any whitespace between the twigil and the variable identifier, as is possible with perls built-in lexical variables: $ foo references the variable $foo. $! foo will most likely cause a compile time error.

  • Long-hand dereferencing syntax is required

    When storing references in twigil variables, the long-hand circumfix dereferencing notation has to be used. @$!foo doesn't cause the twigil variable $!foo to be dereferenced as an array. @{ $!foo }, however, does.

  • Issues when interpolating in strings

    Interpolating twigil variables in strings, such as in my $str = "foo: $.foo";, currently only works reliably for plain scalar twigil variables. Interpolating twigil arrays will not work as expected when trying to interpolate the entire array, a slice of the array, or even just a single element of it. Postfix dereferencing, such as my $str = "$.hash_ref-{foo}"> isn't currently supported either.

AUTHOR

Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Florian Ragwitz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.