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

David E. Wheeler david at kineticode.com
Fri Oct 9 22:20:30 EDT 2009


On Oct 8, 2009, at 5:17 PM, David E. Wheeler wrote:

> It's actually `alias` that has the difference, and only when you alias
> a class that inherits templates from a parent class. I could find a
> place to carp about that case, yes.
>
>> Does that seem like a reasonable way forward?
>
> Works for me, yes.

Looking more closely, I don't think it's possible to identify when the  
user will get one thing but expect the other. Let me see if I can  
explain with a very simple example.

Template class Foo defines template "hello".

Template class Foo::Bar inherits from Foo.

Template class Wifty::UI aliases Foo::Bar under /bar.

So what this means is that Wifty::UI has the template /bar/hello.

Now, everything is nearly the same as it was before: the code in the  
"hello" template can access package variables (if any were set) via ` 
$self->get_package_variable`.

The *only* difference is that $self is now "Foo", whereas before it  
would have been "Foo::Bar". This has no effect on the package  
variables that can be fetched.

The only way in which I can imagine that this would bit a user is if  
they were expecting Foo::Bar. Maybe Foo::Bar had another class method  
that they would want access to. That makes no sense to me, though,  
because the "hello" template is defined in the Foo class, and  
therefore should have no knowledge of its subclasses. 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.

So, the only way I could put in a cluck would be when someone did  
something with the class name passed to the template. The overwhelming  
majority of the time, such use would be legitimate. There is no way  
for me to tell, in the code, that the user was expecting "Foo::Bar"  
but got "Foo".

Make sense? Sorry to be a bit long-winded; I was honestly trying to  
keep it simple. :-)

All that said, I could, with a bit of added complexity, restore the  
passing of Foo::Bar to the hello template defined in Foo, but as I've  
said, I can't really imagine that this wasn't a mistake, given its  
inconsistency compared to `import_templates` and lack of any real  
reason for it being so that I can ascertain.

Sorry, there I go again…

Best,

David


More information about the jifty-devel mailing list