[Catalyst] Catalyst::View::JSON 0.23 with encode_json() support

Tatsuhiko Miyagawa miyagawa at gmail.com
Fri Feb 22 22:42:01 GMT 2008


Hi,

per popular demand, I added and documented the way how you can bypass
JSON::Any and do what you want with your favorite JSON encoder. Quote
from POD,

OVERRIDING JSON ENCODER
       By default it uses JSON::Any to serialize perl data strucuture into
       JSON data format. If you want to avoid this and encode with your own
       encoder (like passing options to JSON::XS etc.), you can implement
       "encode_json" method in your View class.

         package MyApp::View::JSON;
         use base qw( Catalyst::View::JSON );

         use JSON::XS;

         sub encode_json {
             my($self, $c, $data) = @_;
             my $encoder = JSON::XS->new->ascii->pretty->allow_nonref;
             $encoder->encode($data);
         }

         1;

Will be available on CPAN shortly and also from
http://svn.bulknews.net/repos/public/Catalyst-View-JSON/trunk


-- 
Tatsuhiko Miyagawa



More information about the Catalyst mailing list