Please note that the below is pretty much wrong - it appears that this is a bug in older perls

Deparse is often wrong in corner-cases, including this one:

My perl's deparse does better (v5.8.6) (updated to reflect code below):

BEGIN { $^W = 1; } use AA::BB; use strict 'refs'; print "Caught exception $@" unless eval { do { &CORE::GLOBAL::die('AA::BB'->new) } }; test.pl syntax OK

You're better off trying to run the code in any case: yours doesn't work because there is no AA::BB::new method.

update:

#! /usr/bin/perl -w use strict; use AA::BB; eval { die AA::BB->new; } or print "Caught exception $@";
package AA::BB; sub die(@) { print "die called with args '@_'" }; sub import { *CORE::GLOBAL::die = \¨ } sub new { return bless {},shift; } 1;
Output:
die called with args 'AA::BB=HASH(0x81761c8)'
update2 in other words, your code is allright except for the missing new() method, and deparse is wrong. You should do more checking in your code and try not to depend Deparse.

Also, overriding CORE::GLOBAL::die is completely evil: it can easily break exceptions (as my modified code shows).


In reply to Re: perl calls die() as a method by Joost
in thread perl calls die() as a method by kappa

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.