[Catalyst] Catalyst::View::JSON parameters
Jason Kohles
email at jasonkohles.com
Tue Dec 4 14:12:06 GMT 2007
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 = JSON::Any->new(%{$self->params}); # create the copy of JSON
handler
with
my $json = JSON::Any->new( %{ $self->params || {} } ); # create the
copy of JSON handler
> @@ -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) = @_;
> @@ -29,7 +29,7 @@
>
> eval {
> JSON::Any->import($driver);
> - my $json = JSON::Any->new; # create the copy of JSON handler
> + my $json = 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' => {
> + params => {pretty => 1, indent => 2}, # pass
> params to the JSON module
> allow_callback => 1, # defaults to 0
> callback_param => 'cb', # defaults to 'callback'
> expose_stash => [ qw(foo bar) ], # defaults to
> everything
>
> _______________________________________________
> 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.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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20071204/081213a6/attachment.htm
More information about the Catalyst
mailing list