[Templates] How To Throw Exception on Missing Method
Paul Seamons
mail@seamons.com
Thu, 26 Jul 2007 14:11:46 -0600
> Here is some quick untested pseudo code.
And here it is on Template::Alloy:
use Template::Alloy;
use Scalar::Util qw(blessed);
my $tt = Template::Alloy->new(UNDEFINED_ANY => sub {
my ($self, $ident) = @_;
return '' if ! ref $ident;
my ($obj, $args, $dot, $meth) = @$ident;
return '' if ! blessed($obj) || $obj->can($meth);
$self->throw('invalid_method', "Bad method $meth on class ".ref($obj));
});