Skip to content

Instantly share code, notes, and snippets.

@cybersiddhu
Created August 3, 2009 16:27
Show Gist options
  • Save cybersiddhu/160644 to your computer and use it in GitHub Desktop.
Save cybersiddhu/160644 to your computer and use it in GitHub Desktop.
package DictyREST::Renderer::JSON;
use warnings;
use strict;
use Carp;
use version; our $VERSION = qv('1.0.0');
# Other modules:
use base 'Mojo::Base';
use JSON;
use Data::Dumper;
# Module implementation
#
__PACKAGE__->attr('json');
sub new {
my ( $class, %arg ) = @_;
my $self = {};
bless $self, $class;
return $self;
}
sub build {
my ( $self, %arg ) = @_;
$self->json( JSON->new() );
return sub { $self->process(@_); };
}
sub process {
my ( $self, $renderer, $c, $output ) = @_;
return if $c->stash('format') ne 'json';
my $obj = $c->stash('data');
$c->app->log->debug("in json renderer");
#routine to get perl data structure that will be converted to json
$obj->init();
my $conf = $obj->config();
$$output = $self->json->objToJson(
[ map { $_->to_json } @{ $conf->panels } ] );
return 1;
}
1; # Magic true value required at end of module
__END__
=head1 NAME
DictyREST::Renderer::JSON - [JSON renderer for DictyREST application]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment