[Catalyst] Catalyst::View::JSON parameters
Ian Docherty
catalyst at iandocherty.com
Tue Dec 4 15:40:05 GMT 2007
Jason Kohles wrote:
> On Dec 3, 2007, at 4:38 PM, Ian Docherty wrote:
>
>> 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/? =
>>
>> 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).
>>
> Although I like the idea, this patch will blow up on anyone who is =
> already using the package, as you don't provide any defaults for the =
> new accessor. You probably want to replace:
>
> my $json =3D JSON::Any->new(%{$self->params}); # create the copy of JSON =
> handler
>
> with
>
> my $json =3D JSON::Any->new( %{ $self->params || {} } ); # create the =
> copy of JSON handler
Quite right, I had missed that until this morning, I meant to provide an =
update. Thanks for pointing it out.
>
>> @@ -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 =
>> params 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
>>
>> _______________________________________________
>> List: Catalyst at lists.scsys.co.uk <mailto:Catalyst at lists.scsys.co.uk>
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: =
>> http://www.mail-archive.com/catalyst@lists.rawmode.org/
>> Dev site: http://dev.catalyst.perl.org/
>
> -- =
> Jason Kohles, RHCA RHCDS RHCE
> email at jasonkohles.com - http://www.jasonkohles.com/
> "A witty saying proves nothing." -- Voltaire
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.or=
g/
> Dev site: http://dev.catalyst.perl.org/
> =
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071204/986f9=
33d/attachment.htm
More information about the Catalyst
mailing list