> What I want is an error only if $object is undef, or if there is no
> someMethod()   defined, and I want this behavior globally.
>
> What's the best practice for achieving this?

Here is some quick untested pseudo code.

package MyStash;

use base qw(Template::Stash);
use Scalar::Util qw(blessed);

sub undefined {
    my ($self, $ident) = @_;
    return '' if ! ref $ident;

    my ($obj, $args, $meth) = @$ident;
    return '' if ! blessed($obj) || $obj->can($meth);

    $self->throw('invalid_method', "Bad method $meth on class ".ref($obj));
}


# Later in your file

use Template;
use MyStash;

my $tt = Template->new(STASH => MyStash->new);


_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to