Egg::Plugin::JSON - JSON for Egg::Plugin.


NAME

Egg::Release::JSON - JSON for Egg::Plugin.

Back to Top


SYNOPSIS

Controller.

  use Egg qw/ JSON /;

Example code.

  my $json_data = {
    aaaaa => 'bbbbb',
    ccccc => 'ddddd',
    };
  
  #
  # Mutual conversion of JSON data.
  #
  my $json_js   = $e->obj2json($json_data);
  my $json_hash = $e->json2obj($json_js);
  
  #
  # The JSON module object is acquired.
  #
  my $json= $e->json;

Back to Top


DESCRIPTION

It is a plugin to treat JSON.

the JSON manpage module is used. Please refer to the document of the JSON manpage for details.

Back to Top


METHODS

obj2json ( [JSON_DATA] )

It is wraper to the 'objToJson' function of the JSON manpage module.

HASH and ARRAY are given to JSON_DATA.

  my $js= $e->obj2json($local_data);

json2obj ( [JSON_JS] )

It is wraper to the 'jsonToObj' function of JSON module.

The JSON data is given to JSON_JS.

  my $local_data= $e->json2obj($json_js);

json

The object of the JSON manpage module is returned.

  my $json= $e->json;

get_json ( [FILE_PATH] || [REQUEST_METHOD], [URL], [LWP_OPTION])

The JSON code is acquired by the file and URL and the Egg::Plugin::JSON::Result object is returned.

The occurrence of the error can be confirmed by is_success and the is_error method of the returned object.

* When URL is specified, the thing that the Egg::Plugin::LWP manpage can be used.

  my $result= $e->get_json( GET=> 'http://domain/json_code' );
  
  my $json_obj;
  if ($result->is_success and $json_obj= $result->obj) {
    $e->view->param('json_text', $json_obj->{message});
  } else {
    $e->debug_out('JSON ERROR : '. $result->is_error);
    $e->finished(500);
  }

Back to Top


RESULT METHODS

It is a method of Egg::Plugin::JSON::Result that get_json returns.

new

Constructor

is_success

When the data conversion of the obtained JSON code succeeds, true is restored.

obj

Data returns when is_success is true.

is_error

The error message returns when is_success is false.

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::Plugin::JSON - JSON for Egg::Plugin.