[Catalyst] Catalyst::View::JSON parameters

Ian Docherty catalyst at iandocherty.com
Mon Dec 3 21:38:03 GMT 2007


A quick patch that works for me, please see if it is compatible with the =

way you want the code to work. (Apologies if the  patch is not correct, =

I am not too familiar with creating patch files).

Tatsuhiko Miyagawa wrote:
> On 12/3/07, Ian Docherty <catalyst at iandocherty.com> wrote:
>
>   =

>> On looking at the code for C::V::JSON it creates a new JSON::Any object
>> but does not pass on any parameters (probably because there is no
>> standard parameter mappings for the different JSON modules).
>>
>> I am at a loss as to how to do this without writing my own C::V::JSON
>>     =

>
> Can you s/writing my own/submtiting a patch for/?
>
>   =


@@ -9,7 +9,7 @@
 use Catalyst::Exception;
 require JSON::Any;

-__PACKAGE__->mk_accessors(qw( allow_callback callback_param =

expose_stash encoding json_dumper no_x_json_header ));
+__PACKAGE__->mk_accessors(qw( params allow_callback callback_param =

expose_stash encoding json_dumper no_x_json_header ));

 sub new {
     my($class, $c, $arguments) =3D @_;
@@ -29,7 +29,7 @@

     eval {
         JSON::Any->import($driver);
-        my $json =3D JSON::Any->new; # create the copy of JSON handler
+        my $json =3D JSON::Any->new(%{$self->params}); # create the copy =

of JSON handler
         $self->json_dumper(sub { $json->objToJson($_[0]) });
     };

@@ -134,6 +134,7 @@
   MyApp->config({
       ...
       'View::JSON' =3D> {
+          params          =3D> {pretty =3D> 1, indent =3D> 2},  # pass par=
ams =

to the JSON module
           allow_callback  =3D> 1,    # defaults to 0
           callback_param  =3D> 'cb', # defaults to 'callback'
           expose_stash    =3D> [ qw(foo bar) ], # defaults to everything

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071203/c2e18=
917/attachment.htm


More information about the Catalyst mailing list