I only have limited experience in JSON (only 2 apps to my name so far ;)), but the methodology I use is different. Instead of putting the data in the header, I just do a:

sub json_data {
  my $self = shift;
  my $data = $self->_get_json_data(); # or something...
  $self->header_props( -type => 'text/json' );
  my $json = new JSON;
  return $json->objToJson( $data );
}

Then in my javascript code, I eval the response to suck it into the variable space:

function regen_previews( original_request ) {
    var data = eval('(' + original_request.responseText + ')');
//alert( "rec'd the response: " + data );
    for ( var element in data ) {
        $(element).innerHTML = data[element];
    }
}

Ok, so all that said, I'm not sure what a Plugin could bring to this space. Perhaps specifying which runmodes are JSON runmodes and then your runmode would just return the data structure. Then the Plugin would add the header and a call to JSON to convert the object to a JSON-formatted text.

Maybe something like this:

use CGI::Application::Plugin::JSON;

sub setup {
  my $self = shift;
  # ... typical cgiapp setup stuff
  $self->json_runmodes( [ qw( json_data ) ] );
}

sub json_data {
  my $self = shift;
  my $data = $self->_get_json_data();  # or whatever...
  return $data;
}

- Jason

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
             http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to