Egg::Release::JSON - JSON for Egg::View.
Configuration.
VIEW => [ ..... [ JSON => { content_type => 'text/javascript+json', charset => 'UTF-8', option => { pretty => 1, indent => 2 }, } ], ],
Example code.
$e->default_view('JSON')->obj({ hoge=> 'boo', baaa=> 'wii', });
* It leaves it to the operation of Egg now.
It is VIEW to output JSON.
JSON is output by the 'objToJson' function of "JSON " module.
see JSON.
Please add JSON to the setting of VIEW.
VIEW => [ ...... ... [ JSON => { ....... ... } ], ],
Contents type when JSON is output.
Default is 'text/javascript+json'.
Character set when JSON is output.
Default is 'UTF-8'.
Option to pass to objToJson function of JSON module.
option=> { pretty => 1, indent => 2 },
see JSON;
* When following 'x_json' is made effective, the inconvenience is generated because the JSON code is molded when option is set.
When an effective value is set, it comes always to output the JSON data to 'X-JSON' of the response header. When the JSON data is treated with Prototype.js, this is convenient.
* This value invalidates and is good at the thing individually made effective by the 'x_json' method.
Default is 0.
The data to give it to the objToJson function of JSON module is maintained.
It is necessary to define some values like being undefined the first stage.
The value set to call it without giving anything is returned.
# ARRAY is defined. my $array= $e->view('JSON')->obj([]); # HASH is defined. my $hash= $e->view('JSON')->obj({});
Response header (X-JSON) contains the JSON code.
* Please refer to 'x_json' of CONFIGURATION.
$e->view('JSON')->x_json(1); # Output response header. Content-Type: text/javascript+json; charset=utf-8 X-JSON: ({"hoge":11111,"boo":22222})
When 'x_json' is effective, the contents header comes to be output it always followed.
<div>JSON sees in the response header.</div>
The result of the objToJson function of JSON module is returned.
my $view= $e->view('JSON'); my $obj= $view->obj({}); $obj->{hoge}= '11111'; $obj->{booo}= '22222'; my $json_js= $view->render($obj);
It is not necessary to call it from the project code because it is called by the operation of Egg usually.
JSON, Egg::Release,
Masatoshi Mizuno <lushe@cpan.org>
Copyright (C) 2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
L<> starts or ends with whitespace
To install Egg::Release::JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Egg::Release::JSON
CPAN shell
perl -MCPAN -e shell install Egg::Release::JSON
For more information on module installation, please visit the detailed CPAN module installation guide.