DTA::CAB::Format::JSON::XS - Datum parser|formatter: JSON code via JSON::XS


NAME

DTA::CAB::Format::JSON::XS - Datum parser|formatter: JSON code via JSON::XS

(Back to Top)


SYNOPSIS

 use DTA::CAB::Format::JSON::XS;
 
 $fmt = DTA::CAB::Format::JSON::XS->new(%args);
 
 ##========================================================================
 ## Methods: Input
 
 $fmt = $fmt->close();
 $fmt = $fmt->parseJSONString($str);
 $doc = $fmt->parseDocument();
 
 ##========================================================================
 ## Methods: Output
 
 $fmt = $fmt->flush();
 $str = $fmt->toString();
 $fmt = $fmt->putToken($tok);
 $fmt = $fmt->putSentence($sent);
 $fmt = $fmt->putDocument($doc);

(Back to Top)


DESCRIPTION

DTA::CAB::Format::JSON::XS is a DTA::CAB::Format datum parser/formatter which reads & writes data as JSON::XS code using the JSON::XS module.

Globals

Variable: @ISA

DTA::CAB::Format::JSON::XS inherits from DTA::CAB::Format.

Filenames

DTA::CAB::Format::JSON::XS registers the filename regex:

 /\.(?i:yaml|yml)$/

with DTA::CAB::Format.

Constructors etc.

new
 $fmt = CLASS_OR_OBJ->new(%args);

Constructor.

%args, %$fmt:

 ##---- Input
 doc    => $doc,                 ##-- buffered input document
 ##
 ##---- Output
 dumper => $dumper,              ##-- underlying Data::Dumper object
 ##
 ##---- INHERITED from DTA::CAB::Format
 #encoding => $encoding,         ##-- n/a
 level     => $formatLevel,      ##-- sets Data::Dumper->Indent() option
 outbuf    => $stringBuffer,     ##-- buffered output

Methods: Persistence

noSaveKeys
 @keys = $class_or_obj->noSaveKeys();

Override returns list of keys not to be saved. This implementation returns qw(doc outbuf).

Methods: Input

close
 $fmt = $fmt->close();

Override: close currently selected input source.

fromString
 $fmt = $fmt->fromString($string)

Override: select input from the string $string.

parseJSONString
 $fmt = $fmt->parseJSONString($str);

Evaluates $str as perl code, which is expected to return a DTA::CAB::Document object (or something which can be massaged into one), and sets $fmt->{doc} to this new document object.

parseDocument
 $doc = $fmt->parseDocument();

Returns the current contents of $fmt->{doc}, e.g. the most recently parsed document.

Methods: Output

flush
 $fmt = $fmt->flush();

Override: flush accumulated output.

toString
 $str = $fmt->toString();
 $str = $fmt->toString($formatLevel)

Override: flush buffered output document to byte-string. This implementation just returns $fmt->{outbuf}, which should already be a UTF-8 byte-string, and has no need of encoding.

putToken
 $fmt = $fmt->putToken($tok);

Override: writes a token to the output buffer (non-destructive on $tok).

putSentence
 $fmt = $fmt->putSentence($sent);

Override: write a sentence to the outupt buffer (non-destructive on $sent).

putDocument
 $fmt = $fmt->putDocument($doc);

Override: write a document to the outupt buffer (non-destructive on $doc).

(Back to Top)


EXAMPLE

See EXAMPLE in the DTA::CAB::Format::JSON manpage.

(Back to Top)


AUTHOR

Bryan Jurish <jurish@bbaw.de>

(Back to Top)


COPYRIGHT AND LICENSE

Copyright (C) 2010 by Bryan Jurish

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.

(Back to Top)

 DTA::CAB::Format::JSON::XS - Datum parser|formatter: JSON code via JSON::XS