Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
After getting tired of Method::Signatures often reporting the wrong error line, I turned to Function::Parameters, having read somewhere that it didn't have this problem. However, the issues I'm having with Function::Parameters are often worse. When used in conjunction with Moo, the first line where the error occurs is often reported after numerous other lines are reported first, making the root cause hard to find.

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:

"my" variable $cwd masks earlier declaration in same statement at Thin +g.pm line 31.
This error seems meaningless as it's not even in the method loop() where the error (the typo "nnext") actually occurs.

If the method getcwd() is changed to:

method getcwd() { return $self->topdir; }
suddenly the error is correctly reported:
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?

say  substr+lc crypt(qw $i3 SI$),4,5

In reply to Error reporting in Function::Parameters by golux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (None)
    As of 2024-04-25 00:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found