The technique used is a very simplistic transform to allow for using very simplistic named formal
arguments in subroutine declarations. This module does not implement warning if more or fewer parameters
than expected are passed in.
The module also implements default values for unnamed parameters by splitting the formal parameters on
"/,/" and assigning the values if @_ contains fewer elements than expected. Function calls as default
values may work by accident. Commas within default values happen to work due to the design of
Filter::Simple, which removes them for the application of this filter.
Syntaxpeculiarities
Note that this module inherits all the bugs of Filter::Simple and potentially adds some of its own.
Slashes
Most notable is that Filter::Simple sometimes will misinterpret the division operator "/" as a leading
character to starting a regex match:
my $wait_time = $needed / $supply;
This will manifest itself through syntax errors appearing where everything seems in order. The hotfix is
to add a comment to the code that "closes" the misinterpreted regular expression:
my $wait_time = $needed / $supply; # / for Filter::Simple
A better hotfix is to upgrade to Perl 5.20 or higher and use the native signatures support there. No
other code change is needed, as this module will disable its functionality when it is run on a Perl
supporting signatures.
Sizeoperatorinterpretedasreplacement
Filter::Simple sometimes will misinterpret the file size operator on the default filehandle "-s _" as the
start of a replacement
my $filesize = -s _;
# Misinterpreted as
my $filesize = -(s _;..._g);
This will manifest itself through syntax errors appearing where everything seems in order. The hotfix is
to indicate that "<_"> is a filehandle by prefixing it with "<*">:
my $filesize = -s *_;
A better hotfix is to upgrade to Perl 5.20 or higher and use the native signatures support there. No
other code change is needed, as this module will disable its functionality when it is run on a Perl
supporting signatures.
Parenthesesindefaultexpressisons
Ancient versions of Perl before version 5.10 do not have recursive regular expressions. These will not be
able to properly handle statements such as
sub foo ($timestamp = time()) {
}
The hotfix is to rewrite these function signatures to not use parentheses. The better approach is to
upgrade to Perl 5.20 or higher.
Regularexpressionmatchesindefaultexpressions
To keep the argument parser simple, the parsing of regular expressions has been omitted. For Perl below
5.10, you cannot use regular expressions as default expressions. For higher Perl versions, this means
that parentheses, curly braces and commas need to be explicitly escaped with a backslash when used as
default expressions:
sub foo( $x = /,/ ) { # WRONG!
sub foo( $x = /\,/ ) { # GOOD!
sub foo( $x = /[(]/ ) { # WRONG!
sub foo( $x = /[\(]/ ) { # GOOD!
The hotfix is to rewrite these default expressions with explicitly quoted commas, parentheses and curly
braces. The better approach is to upgrade to Perl 5.20 or higher.
Subroutineattributes
Subroutine attributes are currently not supported at all.
LineNumbers
Due to a peculiarity of how Filter::Simple treats here documents in some versions, line numbers may get
out of sync if you use here documents.
If you spread your formal signatures across multiple lines, the line numbers may also go out of sync with
the original document.
"eval"
Filter::Simple does not trigger when using code such as
eval <<'PERL';
use Filter::signatures;
use feature 'signatures';
sub foo (...) {
}
PERL
So, creating subroutines with signatures from strings won't work with this module. The workaround is to
upgrade to Perl 5.20 or higher.
Deparsing
The generated code does not deparse identically to the code generated on a Perl with native support for
signatures.