Re: [Templates] how to see error messages

[prev] [thread] [next] [Date index for 2005/04/14]

From: Dave Howorth
Subject: Re: [Templates] how to see error messages
Date: 10:23 on 14 Apr 2005
Dave Howorth wrote:
> Andy Wardley wrote:
> 
>> Dave Howorth wrote:
>>
>>> my $tt = Template->new();
>>
>>
>> Try this:
>>   my $tt = Template->new( DEBUG => 'undef' );   # yes, the string "u n 
>> d e f"
> 
> 
> Hi Andy,
> 
> Thanks for your reply. The problem with this suggestion is that I also 
> have lots of templates that say things like:
> 
>   [% IF fred ; do_something ; END %]
> 
> This seems like normal TT code to me, but it breaks with that debugging 
> flag. I don't really want to rewrite all my templates just to make 
> debugging one class of error easier.
> 
>>> test.tt
>>> -------
>>> [% USE Test = Class('MyTest') ;
>>>   Test.method() ;
>>>   'success'
>>> %]
>>
>>
>>
>> With the DEBUG flag set as shown, undefined values are thrown as 
>> exceptions:
>>
>>   "undef error - method is undefined"
>>
>> TT treats all data types as equal (more or less).  foo.bar returns the 
>> 'bar' part of 'foo', or undef if it doesn't exist (including a 'bar' 
>> method missing from a 'foo' object).  And by default, TT ignores any 
>> undefined values unless you set the DEBUG => undef flag.
>>
>> I admit it's not entirely obvious or helpful in cases like this, but 
>> that's the way it is I'm afraid.  It may get better in v3...
> 
> 
> I could see the rationale if it was 'method' that was missing. But here 
> the 'bar' part of 'foo' does exist and it runs. Then it throws an 
> exception and normally TT will catch that exception and report it. But 
> here it apparently singles out a particular type of exception and 
> chooses to leave me in ignorance.
> 
> Still, at least I know where I stand now.
> 
> I'm wondering if I could patch it. Is there extra code somewhere that 
> detects this special case? Or is there (IMHO) not quite enough code 
> checking the results wherever the method is invoked?

In case anybody's interested, the following patch to the stash makes it 
continue to ignore missing methods on template objects as per the 
defined behaviour but changes it to not ignore execution failures within 
methods that do exist. The change to the RE is borrowed from Class::DBI. 
Sorry, I don't know xs so providing the equivalent patch for Stash.xs 
line 523 would take more time than I have right now.

Cheers, Dave

--- Template/Stash.pm	Mon Oct  4 11:27:39 2004
+++ Template/Stash.pm	Thu Apr 14 11:10:02 2005
@@ -655,7 +655,8 @@
              # object then we assume it's a real error that needs
              # real throwing

-            die $@ if ref($@) || ($@ !~ /Can't locate object method/);
+            die $@ if ref($@) ||
+                ($@ !~ /Can't locate object method "\Q$item\E/);

              # failed to call object method, so try some fallbacks
  # patch from Stephen Howard



_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] how to see error messages
Dave Howorth 12:36 on 11 Apr 2005

Re: [Templates] how to see error messages
merlyn (Randal L. Schwartz) 14:45 on 11 Apr 2005

Re: [Templates] how to see error messages
merlyn (Randal L. Schwartz) 14:51 on 11 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 15:09 on 12 Apr 2005

Re: [Templates] how to see error messages
Andy Wardley 07:24 on 13 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 09:36 on 13 Apr 2005

Re: [Templates] how to see error messages
Dave Howorth 10:23 on 14 Apr 2005

Generated at 09:31 on 27 Apr 2005 by mariachi v0.52