[jifty-devel] Difference Between alias and import_templates in Template::Declare

David E. Wheeler david at kineticode.com
Sat Oct 10 00:58:39 EDT 2009


On Oct 9, 2009, at 7:20 PM, David E. Wheeler wrote:

> Maybe Foo::Bar
> overrode a method defined in Foo. That might lead to something
> unexpected. But I have a hard time believing that anyone would have
> done this, not least because these are classes with class attributes,
> not objects. So there isn't really much in the way of state.

Shawn found one regression against my branch in the Jifty tests, and  
it appears that this is exactly the case being tested. Here's one of  
the three failures:

> not ok 12 - found content '/base/list=TestApp::View::instance/ 
> instance/view=TestApp::View::instance/instance/ 
> view=TestApp::View::instance'
>
> #   Failed test 'found content '/base/list=TestApp::View::instance/ 
> instance/view=TestApp::View::instance/instance/ 
> view=TestApp::View::instance''
> #   at t/TestApp/t/15-template-subclass.t line 73.
> #     searched: "/base/list=TestApp::View::base/base/ 
> view=TestApp::"...
> #   can't find: "/base/list=TestApp::View::instance/instance/ 
> view=T"...
> ok 13 - get 'http://localhost:11379: /jifty/jifty/trunk/t/TestApp/t/ 
> 15-template-subclass.t /instance/list_ht'

In these tests, TestApp::View::instance subclasses  
TestApp::View::base. The templates in the latter output

     outs("/base/list=$self");

So it fails because, with my changes, $self is ::base instead  
of ::instance. That just demonstrates the point, and at first I just  
assumed that the tests could perhaps be changed. However, looking at  
the template classes, I see that both ::base and ::instance implement  
a base_path() method. ::instance overrides its the implementation in  
base. Therefor, when the base templates call

	show($self->base_path.'/view');

it's relying on getting the value for the method returned by the  
implementation in ::instance. So this does seem to be the the one way  
I could see that the existing behavior might have been correct.

So it leads me to wonder: Could it be that the behavior of  
`import_templates`, which always passes in the class in which a method  
is defined, could be wrong? I'm wondering now whether, if I changed it  
so that `import_methods` works like `alias` in this way, would there  
be other regressions?

In other words, what happens if I make `import_temlates` consistent  
with `alias` instead of the other way around, with respect to the  
class name passed to the template? Do you think that would make more  
sense?

Thanks,

David


More information about the jifty-devel mailing list