The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MojoX::Renderer::JSON - JSON renderer for Mojo

SYNOPSIS

  use MojoX::Renderer::JSON;

  sub startup {
    my $self = shift;

    $self->types->type(json => 'application/json');

    my $render = MojoX::Renderer::JSON->build(
      canonical => 1,
      utf8      => 1,
    );

    $self->renderer->add_handler(json => $render);
  }

DESCRIPTION

Once added this renderer will be called by MojoX::Renderer for any given template where the suffix of the specified template matches the suffix used in the add_handler method.

This renderer converts the result element in the stash to JSON using the given options. The template name is ignored.

METHODS

build

This method returns a handler for the Mojo renderer.

Supported parameters are any method defined in JSON, the given value will be passed as an argument.

If you need to specify other class than JSON (eg. JSON::XS or some subclass) you can use:

  my $render = MojoX::Renderer::JSON->build(
    json_class  => 'MyJSON',
    json_params => [ canonical => 1, param1 => 'value1' ],
  );

AUTHOR

Graham Barr <gbarr@cpan.org>

BUGS

Please report any bugs or feature requests to bug-mojox-renderer-json at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MojoX-Renderer-JSON. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

JSON, MojoX::Renderer

COPYRIGHT & LICENSE

Copyright (C) 2008 Graham Barr

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.