Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've been testing a lot of modules with bleadperl and have run into a few issues with some modules, but for the most part modules have installed just fine. There have been one rather common issue with some CPAN authors' use of Carp. In normal code, it will probably look like this.

use warnings; use strict; sub complain { require Carp; Carp::carp "This should not work!"; }

Here's a one-liner with Perl 5.8.8 and bleadperl that demonstrates the problem.

[steve@kirk ~]$ perl -Mstrict -Mwarnings \ -le'sub complain{ require Carp; Carp::carp "This should not work!"; } +\ complain' This should not work! at -e line 1 main::complain() called at -e line 1 [steve@kirk ~]$ /tmp/bleadperl/bin/perl5.9.5 -Mstrict \ > -Mwarnings -le'sub complain{ require Carp;\ > Carp::carp "This should not work!"; } complain' String found where operator expected at -e line 2, near "Carp::carp "T +his shoulld not work!"" (Do you need to predeclare Carp::carp?) syntax error at -e line 2, near "Carp::carp "This should not work!"" Execution of -e aborted due to compilation errors.

What's the difference? The code above is relying on some undefined behavior of warnings.pm. warnings used Carp which would invade the namespaces of other modules that used warnings. With change #23768, warnings was changed to only require Carp when it is needed. Without some module using Carp and importing it into the global namespace, it turns into another bareword, unless you put parentheses around your arguments.

[steve@kirk ~]$ /tmp/bleadperl/bin/perl5.9.5 -Mstrict \ -Mwarnings -le'sub complain{ require Carp; \ Carp::carp("This will work!"); } complain' This will work! at -e line 1 main::complain() called at -e line 2

How common is this problem? Common enough, I guess. I’ve so far tested around 800 CPAN distributions with bleadperl, and have seen around ten modules fail with this problem. That’s just over 1% of the modules. This figure may go up or down, since it seems to correlate to the CPAN author, rather than something happening at random. If an author uses the require Carp idiom incorrectly once, it seems pretty likely that they’ll do it again. This may hit non-CPAN code a bit harder since error handling routines are typically copy-and-pasted around or placed in a common module. If done incorrectly, it could bring down an application, or a whole suite of applications.

So, please, please, please, test your modules with bleadperl! Its better to do it now rather than wait for Perl 5.10 to be released. See my signature for details on how to get a bleadperl and test with it.


Steve_p

Test your modules with bleadperl!

  rsync -avz rsync://public.activestate.com/perl-current/ .
  ./Configure -des -Dusedevel -Dprefix=/path/to/test/perl
  make test
  make install

Now, please test you modules! If you have test failures that don't happen with Perl 5.8.8, send a simplified test case to

perlbug at perl.org


In reply to "require Carp" may be hazardous to your code by Steve_p

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 studying the Monastery: (2)
As of 2024-04-26 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found