Plugin::JSON::Escape;
use strict;
use warnings;
use base qw/Template::Plugin/;
use JSON ();
our $VERSION = 0.02;
sub new {
my ($class, $context, $args) = @_;
my $self = bless { json => unde
$self->json_encode( @_ ) };
$context->define_vmethod( $_ => json => $encode ) for qw/hash list scalar/;
$context->define_filter( json => \&json_filter );
return $self;
}
sub json {
return $self->{json} if $self->{json};
my $json = JSON->new->allow_nonref;
my $args = $self->{args};
for ( keys %$args ) {
$json->$_( $args->{ $_ } ) if $json->can( $_ );
}