1 package SL::Template::Plugin::JSON;
5 use base qw(Template::Plugin);
10 my ($class, $context, $args) = @_;
12 my $self = bless {context => $context, json_args => $args }, $class;
14 $context->define_vmethod($_, json => sub { $self->json(@_) }) for qw(hash list scalar);
20 my ($self, %params) = @_;
23 $self->{json} = JSON->new->allow_nonref(1);
25 my $args = $self->{json_args};
27 for my $method (keys %$args) {
28 if ( $self->{json}->can($method) ) {
29 $self->{json}->$method( $args->{$method} );
38 my ($self, $value) = @_;
40 $self->json_converter->encode($value);
44 my ( $self, $value ) = @_;
46 $self->json_converter->decode($value);