On Tue, 25 May 2010, Kenneth Graves wrote:

In the simple case (known methods/no side effects), then one of Uri's solutions 
will work.

For the case of unknown methods, a two pass solution might work: collect the 
method names from the template, then call them with $object->$method() syntax, 
then interpolate the results.

Unfortunately, unless the perl compiler can magically delay execution in some way, you then end up calling every single method to get its value, even if you only need a couple of them. These objects have over 100 methods. Also, some of the methods might have side effects, like ->delete.


For something yet complicated, Template::Toolkit can handle objects in 
templates.  See 
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Manual/Variables.pod
 for the details.  If you can't change the template language, then 
preprocessing what you have to make it TT-compatible is another option.

It looks like TT has a perl-like interpolation mode so you can use $var instead of [%var%]. It looks like it would work if I iterate over my namespace as I did before to construct the variables hash for TT, with a bunch of

 $symbol => sub { $object->$symbol() }

that does get away from the eval and the tied scalar, thanks.

TT is big, so make sure this isn't a case of using a bazooka to swat a fly.

Fair point. If it works it will be worth it.


--kag


_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm


--
 - Alex Aminoff
   BaseSpace.net

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to