kappa has asked for the wisdom of the Perl Monks concerning the following question:
Yes, perl does consider my die an indirect object method call. I checked with B::Deparse. And the question is -- how to prevent the situation?
My code (I tried to implement something like My::Exception class from this perl.apache.org doc) is below.
File AA/BB.pm
File testdie.pl:package AA::BB; sub die(@) { die @_ }; sub import { *CORE::GLOBAL::die = \¨ } 1;
Deparsed test.pl:#! /usr/bin/perl -w use strict; use AA::BB; eval { die AA::BB->new; };
% perl -MO=Deparse testdie.pl eval { 'AA::BB'->CORE::GLOBAL::die->new; };
I'd really like to throw exceptions without additional parens like this: die MyApp::Error->new() and this very syntax is everywhere on the web.
Ah, and this is perl 5.6.2.
Update: looks like a bug fixed somewhere between 5.6.2 and 5.8.7. So the new question is: is there a way to force die() as a sub? Upgrading perl is not an option for me due to different Unicode :(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl calls die() as a method
by Joost (Canon) on Aug 18, 2005 at 14:37 UTC | |
by chibiryuu (Beadle) on Aug 18, 2005 at 14:57 UTC | |
by Joost (Canon) on Aug 18, 2005 at 16:02 UTC | |
by kappa (Chaplain) on Aug 18, 2005 at 15:11 UTC | |
|
Re: perl calls die() as a method
by chromatic (Archbishop) on Aug 18, 2005 at 16:52 UTC |