in reply to [SOLVED] YAML, $SIG{__DIE__}, Log4perl, $^S, and eval{}

How about adding
use MyModuleWhichExports_die;
where MyModuleWhichExports_die exports a custom sub die { } which does whatever you need it to do?

Or how about replacing each die with LOGDIE from  use Log::Log4perl qw(:easy);

Replies are listed 'Best First'.
Re^2: YAML, $SIG{__DIE__}, Log4perl, $^S, and eval{}
by ateague (Monk) on Mar 21, 2014 at 14:18 UTC
    How about adding use MyModuleWhichExports_die; where MyModuleWhichExports_die exports a custom sub die { } which does whatever you need it to do?

    Thanks for that. I did not realize you could overwrite Perl's built-in functions that way. This is pretty much what I am looking for.

    Quick (possibly dumb)question:
    Is it possible to inline MyModuleWhichExports_die in the main program and have it "export" the custom die() function?
    e.g.:

    package MyModuleWhichExports_die; # Something like Export's "@EXPORT" list here sub die { CORE::die "New and improved!: @_"; } package main; die "I want to be prefixed with 'New and improved'";

    I know I can do that by using the fully qualified name of my custom die() (MyModuleWhichExports_die::die), but that defeats the whole purpose of writing a wrapper so I don't have to change my original die() calls in the code

Re^2: YAML, $SIG{__DIE__}, Log4perl, $^S, and eval{}
by ateague (Monk) on Mar 21, 2014 at 14:26 UTC
    (Sorry for the double reply, I can't seem to edit my first reply yet)
    Or how about replacing each die with LOGDIE from use Log::Log4perl qw(:easy);

    That is what I am trying to avoid. The whole raison d'être of this is to seamlessly add Log4perl to an existing script without having to go hunt down and change all the die() (and warn()) calls in the code.

      without having to go hunt down and change all the die() (and warn()) calls in the code.

      But you don't have to do that, you just have to add use whateveritwasthatexportsdie;; to the top of each module ... no search/replace