Subject: | Confusing error messages caused by references to undefined variables |
MooseX::Method::Signatures comes out with a strange error when you have
references to undefined variables.
Here is some example code to explain:
# foo.pm
package Foo;
use Moose;
use MooseX::Method::Signatures;
method broken {
$undefined;
}
method id(Int :$foo) {
return $foo;
}
1;
__END__
#foo.pl
#!/usr/bin/perl
use strict;
use warnings;
use Foo;
my $test = Foo->new;
print $test->id(foo => 3);
__END__
There is a bug: the method Foo::broken contains a reference to the
undefined variable $undefined. But the error message I get is:
')' expected whilst parsing signature near 'Int :' in 'Int :$foo' at
D:/strawberry/perl/site/lib/MooseX/Method/Signatures/Meta/Method.pm line 209
Compilation failed in require at foo.pl line 6.
BEGIN failed--compilation aborted at foo.pl line 6.
Rather than complain about the undefined variable, it complains about
the method signature. (Commenting out the $undefined; line causes the
code to execute successfully, with no problems in the signature.)
Subject: | foo.pm |
package Foo;
use Moose;
use MooseX::Method::Signatures;
method broken {
$undefined;
}
method id(Int :$foo) {
return $foo;
}
1;
Subject: | foo.pl |
#!/usr/bin/perl
use strict;
use warnings;
use Foo;
my $test = Foo->new;
print $test->id(foo => 3);