Egg::View::JSON - JSON for Egg::View.


NAME

Egg::Release::JSON - JSON for Egg::View.

Back to Top


SYNOPSIS

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.

Back to Top


DESCRIPTION

It is VIEW to output JSON.

JSON is output by the 'objToJson' function of JSON module.

see the JSON manpage.

Back to Top


CONFIGURATION

Please add JSON to the setting of VIEW.

  VIEW => [
    ......
    ...
    [ JSON => {
      .......
      ...
      } ],
    ],

content_type

Contents type when JSON is output.

Default is 'text/javascript+json'.

charset

Character set when JSON is output.

Default is 'UTF-8'.

option

Option to pass to objToJson function of the JSON manpage module.

  option=> { pretty => 1, indent => 2 },

see the JSON manpage;

* When following 'x_json' is made effective, the inconvenience is generated because the JSON code is molded when option is set.

x_json

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.

Back to Top


METHODS

obj ( {[HASH or ARRAY or etc.]} )

The data to give it to the objToJson function of the JSON manpage 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({});

x_json ( [BOOL] )

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>

render

The result of the objToJson function of the JSON manpage module is returned.

  my $view= $e->view('JSON');
  my $obj= $view->obj({});
  $obj->{hoge}= '11111';
  $obj->{booo}= '22222';
  
  my $json_js= $view->render($obj);

output

It is not necessary to call it from the project code because it is called by the operation of Egg usually.

Back to Top


SEE ALSO

the JSON manpage, the Egg::Release manpage,

Back to Top


AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

Back to Top


COPYRIGHT

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.

Back to Top

 Egg::View::JSON - JSON for Egg::View.