DOKK / manpages / debian 11 / openguides / OpenGuides::JSON.3pm.en
OpenGuides::JSON(3pm) User Contributed Perl Documentation OpenGuides::JSON(3pm)

Renders the given node as JSON
Renders the given arbitary data as JSON

OpenGuides::JSON - An OpenGuides plugin to output JSON.

Does all the JSON stuff for OpenGuides. Distributed and installed as part of the OpenGuides project, not intended for independent installation. This documentation is probably only useful to OpenGuides developers.

    use Wiki::Toolkit;
    use OpenGuides::Config;
    use OpenGuides::JSON;
    my $wiki = Wiki::Toolkit->new( ... );
    my $config = OpenGuides::Config->new( file => "wiki.conf" );
    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
                                         config => $config );
    # JSON version of a node.
    print "Content-Type: application/javascript\n\n";
    print $json_writer->emit_json( node => "Masala Zone, N1 0NU" );
    # Ten most recent changes.
    print "Content-Type: application/javascript\n";
    print "Last-Modified: " . $self->json_timestamp( items => 10 ) . "\n\n";
    print $json_writer->make_recentchanges_json( items => 10 );

    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
                                           config => $config );
    

"wiki" must be a Wiki::Toolkit object and "config" must be an OpenGuides::Config object. Both arguments mandatory.

    $wiki->write_node( "Masala Zone, N1 0NU",
                     "Quick and tasty Indian food",
                     $checksum,
                     { comment  => "New page",
                       username => "Kake",
                       locale   => "Islington" }
    );
    print "Content-Type: application/javascript\n\n";
    print $json_writer->emit_json( node => "Masala Zone, N1 0NU" );
    

Note: Some of the fields emitted by the JSON generator are taken from the node metadata. The form of this metadata is not mandated by Wiki::Toolkit. Your wiki application should make sure to store some or all of the following metadata when calling "write_node":

Returns a raw Wiki::Toolkit::Plugin::JSON object created with the values you invoked this module with.
    my $json_writer = OpenGuides::JSON->new( wiki   => $wiki,
                                             config => $config );
    print $json_writer->make_prefs_json();
    

Retrieves the preferences from any stored preferences cookie, supplies defaults for any preferences not set, returns the result as JSON.

    # Ten most recent changes.
    print "Content-Type: application/javascript\n";
    print "Last-Modified: " . $json_writer->json_timestamp( items => 10 ) . "\n\n";
    print $json_writer->make_recentchanges_json( items => 10 );
    # All the changes made by bob in the past week, ignoring minor edits.
    my %args = (
                 days               => 7,
                 ignore_minor_edits => 1,
                 filter_on_metadata => { username => "bob" },
               );
    print "Content-Type: application/javascript\n";
    print "Last-Modified: " . $json_writer->json_timestamp( %args ) . "\n\n";
    print $json_writer->make_recentchanges_json( %args );
    
    print "Last-Modified: " . $json_writer->json_timestamp( %args ) . "\n\n";
    

Returns the timestamp of the RSS feed in POSIX::strftime style ("Tue, 29 Feb 2000 12:34:56 GMT"), which is equivalent to the timestamp of the most recent item in the feed. Takes the same arguments as make_recentchanges_json(). You will most likely need this to print a Last-Modified HTTP header so user-agents can determine whether they need to reload the feed or not.

  • Wiki::Toolkit
  • <http://openguides.org/>
  • <http://chefmoz.org/>

The OpenGuides Project (openguides-dev@openguides.org)

Copyright (C) 2003-2013 The OpenGuides Project. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Code in this module is mostly pirated from OpenGuides::RDF, those authors deserve all the credit. Chris Prather did the pirating.

2021-01-30 perl v5.32.0