puterboy has asked for the wisdom of the Perl Monks concerning the following question:
Unfortunately, one of the modules I am using (Weather::Com), liberally uses 'die' subroutines for non-fatal errors such as not being able to reach the weather.com server. This causes my whole Perl script to die, when at most I might want to warn and either ignore or try again.
So, without modifying the module itself, I would like to change the actions of all embedded 'die' commands to 'warn'.
The only way I can see to do that is to wrap each call to such a subroutine in Weather::Com as follows:
1. Is this the best/simplest way to do what I want?
2. Does wrapping in 'eval' (and changing $SIG{__DIE__} locally) have the potential to cause any additional and potentially undesirable side effects?
So, without modifying the module itself, I would like to change the actions of all embedded 'die' commands to 'warn'.
The only way I can see to do that is to wrap each call to such a subroutine in Weather::Com as follows:
My questions are:{ local $SIG{__DIE__} = sub { warn(@_); }; eval { weather_subroutine(); }; }
1. Is this the best/simplest way to do what I want?
2. Does wrapping in 'eval' (and changing $SIG{__DIE__} locally) have the potential to cause any additional and potentially undesirable side effects?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Best way to replace 'die' with 'warn'
by dsheroh (Monsignor) on Dec 06, 2009 at 10:22 UTC | |
by puterboy (Scribe) on Dec 06, 2009 at 10:56 UTC | |
by puterboy (Scribe) on Dec 06, 2009 at 18:13 UTC | |
Re: Best way to replace 'die' with 'warn' (no __DIE__)
by tye (Sage) on Dec 06, 2009 at 06:39 UTC | |
Re: Best way to replace 'die' with 'warn'
by bv (Friar) on Dec 06, 2009 at 03:59 UTC | |
by puterboy (Scribe) on Dec 06, 2009 at 10:36 UTC | |
Re: Best way to replace 'die' with 'warn'
by Marshall (Canon) on Dec 06, 2009 at 04:50 UTC |
Back to
Seekers of Perl Wisdom