| JSORB documentation | Contained in the JSORB distribution. |
JSORB::Server::Traits::WithDebug - A debugging trait for JSORB::Server::Simple
JSORB::Server::Simple->new_with_traits(
traits => [ 'JSORB::Server::Traits::WithDebug' ],
dispatcher => JSORB::Dispatcher::Path->new(
namespace => $ns,
)
)->run;
This is a trait meant to be used with JSORB::Server::Simple to aid in debugging. It basically prints out nicely formatted ASCII tables to STDERR.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Stevan Little <stevan.little@iinteractive.com>
Copyright 2008-2010 Infinity Interactive, Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| JSORB documentation | Contained in the JSORB distribution. |
package JSORB::Server::Traits::WithDebug; use Moose::Role; use Text::SimpleTable; use JSON (); our $VERSION = '0.04'; our $AUTHORITY = 'cpan:STEVAN'; around 'build_handler' => sub { my $next = shift; my $self = shift; my $handler = $self->$next(@_); return sub { my $request = shift; my $t = Text::SimpleTable->new(15, 55); $t->row('Request', $request->uri); $t->row('Method', $request->method); my $params = $request->uri->query_form_hash; my $t2 = Text::SimpleTable->new([ 15, 'Parameter' ], [ 55, 'Value' ]); $t2->row($_, $params->{$_}) for sort keys %$params; warn $t->draw, "\n", $t2->draw, "\n"; my $response = $handler->($request); my $t3 = Text::SimpleTable->new(15, 55); $t3->row( 'Response' => JSON->new->pretty(1)->encode( JSON->new->decode( $response->content ) ) ); warn $t3->draw, "\n"; return $response; } }; no Moose::Role; 1; __END__