1 package SL::Template::Plugin::JSON;
6 use base qw(Template::Plugin);
11 my ($class, $context, $args) = @_;
13 my $self = bless {context => $context, json_args => $args }, $class;
15 $context->define_vmethod($_, json => sub { $self->json(@_) }) for qw(hash list scalar);
21 my ($self, %params) = @_;
24 $self->{json} = JSON->new->allow_nonref(1)->convert_blessed(1);
26 my $args = $self->{json_args};
28 for my $method (keys %$args) {
29 if ( $self->{json}->can($method) ) {
30 $self->{json}->$method( $args->{$method} );
39 my ($self, $value) = @_;
41 $self->json_converter->encode($value);
45 my ( $self, $value ) = @_;
47 $self->json_converter->decode($value);