golux has asked for the wisdom of the Perl Monks concerning the following question:
Worse, the error reported may have nothing to do with the actual error!
Consider the following module "Thing.pm":
package Thing; use Moo; has topdir => ( is => 'rw', required => 1, ); use strict; use warnings; use Function::Parameters; # Methods method loop() { while (1) { my $val = rand(100); if ($val > 80) { # Do nothing if value is over 80 nnext; # This line has the actual error } ($val < 20) and return $val; } } method getcwd() { my $cwd = $self->topdir; return $cwd; }
Running perl -c Thing.pm produces (at least for me) this error:
This error seems meaningless as it's not even in the method loop() where the error (the typo "nnext") actually occurs."my" variable $cwd masks earlier declaration in same statement at Thin +g.pm line 31.
If the method getcwd() is changed to:
suddenly the error is correctly reported:method getcwd() { return $self->topdir; }
perl -c Thing.pm Bareword "nnext" not allowed while "strict subs" in use at Thing.pm li +ne 21. syntax error at Thing.pm line 29, near ") {" Global symbol "$self" requires explicit package name at Thing.pm line +30. Thing.pm had compilation errors.
Note that my original module is almost 2,000 lines, and the error not at all obvious until I started making random changes to try to get Function::Parameters to reveal it.
Does anyone know why this would be the case? Should I be using a different module for type signatures (besides Method::Signatures and Function Parameters)? Or is there some workaround I'm unaware of?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error reporting in Function::Parameters -- or by Moo?
by Discipulus (Canon) on May 31, 2018 at 19:42 UTC | |
by Haarg (Priest) on Jun 01, 2018 at 03:36 UTC | |
|
Re: Error reporting in Function::Parameters
by anonymized user 468275 (Curate) on May 31, 2018 at 23:18 UTC |