Re: [Perl-widget-developer] Widget and templates - QED - stringify overloading
Status: Alpha
Brought to you by:
spadkins
From: Stephen A. <ste...@of...> - 2001-06-08 17:41:04
|
At 10:10 AM 6/8/2001 -0700, ja...@la... wrote: >There were a couple of good points about my proposed how to use widgets in Templating systems. I know the thought of changing a system like Template Toolkit is unattractive. In the long run I feel a few strategic changes could make all lives easier. > >HOWEVER - GET THIS: > >I thought to myself if we do something like: > $widget=[ a widget instance ]; > print $widget; > >We get a lovely output like: > Widget::HTML::Thinggy=HASH(0x80903040) > >Using the overload (perldoc overload) package we can simply overload the stringify operator to whatever we wish: > >Pacakge Widget::HTML::Thinggy; > >sub render_html { >} > >use overload '""' => \&render_html; # or *whatever* Good idea. >Now print $widget will actually call render_html to create what to print. Delicious. > >I can rip out the funky code I whacked into Template Toolkit and still just place my widget where I want, calling it by name and seeing its default rendering (HTML) in all its glory. > >We should look at putting this into the Widget::HTML::Base.pm package. > Good idea. >use overload '""' => \&render; # Does this inherit properly? Maybe not. Might need a bit of fancy footwork for subclasses to Widget::HTML::Base Give this a try and let us know what works. Stephen |