Hi Alex,
after 'sleeping' the whole weekend about that here my suggestion:
####################### - if you write BEGIN { *CORE::GLOBAL::die = &__PACKAGE__::die; }
then we run into problems if the 'die' is called from inside a package, because you get the error message unknown subroutine for '__PACKAGE__::die'
That's why I tried: BEGIN { $SIG{__DIE__} = ¨
######################## - we also have to catch a 'warn' statement within an 'eval block'
That's why include the subroutine warn. Otherwise you get an error message for an unknown routine.
######################## - I change the id subroutine to get really the line which emitted the exception. Example:
#!/usr/bin/perl -w
use Foundation;
$f= NSString->foo("H");
will write something like this: **** ERROR **** PerlObjCBridge: sendObjcMessage: Can't get NSMethodSignature for message "foo" **** ERROR **** PerlObjCBridge: error sending message foo at /System/ Library/Perl/Extras/5.8.6/darwin-thread-multi-2level/ PerlObjCBridge.pm line 230.
But here I don't know which line of my script emitted this error. After my changes at the subroutine id now I get: **** ERROR **** PerlObjCBridge: sendObjcMessage: Can't get NSMethodSignature for message "foo" **** ERROR **** PerlObjCBridge: error sending message foo at /System/ Library/Perl/Extras/5.8.6/darwin-thread-multi-2level/ PerlObjCBridge.pm line 230. in untitled.pl at line 5
What I'm done here is to call 'caller' as long as the return is defined; go one level back and ask whether the exception/warn was called from inside of an eval block.
######################## - if 'die' is called from inside of 'eval' the handler writes the message and the script is running further exit($!) if (!$^S);
######################## - to output the real content of $message I wrote a tiny htmlize subroutine
######################## - to avoid redundancy I wrote two tiny subroutines for file name checking and printing
######################## - to avoid an error on a closed file handle if warn and die occur within an eval block I specified BEGIN { $SIG{__DIE__} = ¨ my $error_fd = $ENV{"TM_ERROR_FD"}; open (TM_ERROR_FD, ">&=$error_fd"); }
END { print TM_ERROR_FD "</div>"; close (TM_ERROR_FD); }
########################
I tested it several times and it seems that it works. Comments?
All the best,
Hans