[TxMt] tiny improvements for perlmate.rb

Alexander Ross alex.j.ross at gmail.com
Thu Nov 30 16:51:35 UTC 2006


Hans,

The the reason we don't want to handle errors that were throw in eval  
blocks is the reason you mentioned.  Typically, the user handles the  
error themself.  But it is bad that $@ refers to exception_handler.pm  
line 34 after a die.  I think we can fix this somehow.

Also, for things that are errors, they should be written to  
TM_ERROR_FD.  Something written to STDERR that isn't an error should  
be left alone.  Would it be possible to filter STDERR from a perl  
module that we can load using the -m switch?

- Alex

On Nov 30, 2006, at 2:06 AM, Hans-Joerg Bibiko wrote:

> Hi Alex
>
> On 30 Nov 2006, at 09:15, Alexander Ross wrote:
>
>> I've just committed an improved PerlMate.  PerlMate now causes  
>> perl to
>> load  exception_handler.pm before executing the user code.
>> exception_handler.pm overrides CORE::GLOBAL::die to format unhandled
>> exceptions and print them to the file descriptor given by the
>> environment varibale TM_ERROR_FD.  This let's us manipulate the  
>> actual
>> exception objects instead of just their string representations.
>>
>> The implementation is very basic, as I have no actual Perl  
>> programming
>> experience.  But it handles `die "Sometext";` just fine.  I don't  
>> know
>> how it will react to the throwing of except objects.
>
> I just checked your exception handler. It works fine as long as you  
> use 'die' mot in a 'eval' environment.
> In Perl you often write your own handler like this:
>
> Example:
> _______________________
> #!/usr/bin/perl -w
>
> $a =  5;
> $b = -1;
>
> eval {
>    $c = $a / $b;
>    die "Denominator cannot be negative" if ($b < 0);
> };
>
> print "Run-time error: $@";
> _________________________
>
> If I run this the 'die' output never reaches your exception handler  
> because of
>
> if($^S) {
> 	CORE::die($@);
> }...
>
> Perl's $@ refers now to exception_handler.pm line 34 and this is  
> not what I want to see.
>
> Why did you choose this 'if clause' to call CORE::die?
>
> If you leave it out and take only the else clause it works. (?)
>
> On the other hand you have a small typo in line 55 of  
> exception_handler.pm
>
> corrected:
> print TM_ERROR_FD '<tr><td>in <a href="txmt://open?' . $url .  
> '&line=' . $line . '"> ' . $display_name . "</a> at line $line<td></ 
> tr>\n" ;
>
> because:
>
> print '$line' will print "$line" not the content of the variable  
> $line.
>
>
> ###########
>
> I wrote a small error/warning formatter in my posted perlmate.rb.  
> Would it better to use TM_ERROR_FD instead of
>
> class PerlMate < ScriptMate
>   def filter_stderr(str)
> ...
> ?
>
> -Hans
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate




More information about the textmate mailing list