NAME

DTA::CAB::Format::YAML - Datum parser|formatter: YAML code (generic)

SYNOPSIS

use DTA::CAB::Format::YAML;

$fmt = DTA::CAB::Format::YAML->new(%args);

##========================================================================
## Methods: Input

$fmt = $fmt->close();
$doc = $fmt->parseDocument();
$fmt = $fmt->parseYAMLString($str);   ##-- abstract

##========================================================================
## Methods: Output

$fmt = $fmt->flush();
$str = $fmt->toString();
$fmt = $fmt->putToken($tok);         ##-- abstract
$fmt = $fmt->putSentence($sent);     ##-- abstract
$fmt = $fmt->putDocument($doc);      ##-- abstract

DESCRIPTION

DTA::CAB::Format::YAML is a DTA::CAB::Format datum parser/formatter which reads & writes data as YAML code. It really acts as a wrapper for the first available subclass among:

DTA::CAB::Format::YAML::XS
DTA::CAB::Format::YAML::Syck
DTA::CAB::Format::YAML::YAML

Globals

Variable: @ISA

DTA::CAB::Format::YAML inherits from DTA::CAB::Format.

Filenames

DTA::CAB::Format::YAML 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.

parseYAMLString
$fmt = $fmt->parseYAMLString($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).

EXAMPLE

An example typed file in the format accepted/generated by this module is:

--- !!perl/hash:DTA::CAB::Document
body:
- !!perl/hash:DTA::CAB::Sentence
  lang: de
  tokens:
  - !!perl/hash:DTA::CAB::Token
    text: wie
    errid: ec
    exlex: wie
    hasmorph: '1'
    lang:
    - de
    moot:
      lemma: wie
      tag: PWAV
      word: wie
    msafe: '1'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: wie
  - !!perl/hash:DTA::CAB::Token
    text: oede
    moot:
      lemma: öde
      tag: ADJD
      word: öde
    msafe: '0'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: oede
  - !!perl/hash:DTA::CAB::Token
    text: '!'
    errid: ec
    exlex: '!'
    moot:
      lemma: '!'
      tag: $.
      word: '!'
    msafe: '1'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: '!'

The same example without YAML typing should also be accepted, or produced with output formatting level=0:

---
body:
- lang: de
  tokens:
  - text: wie
    errid: ec
    exlex: wie
    hasmorph: '1'
    lang:
    - de
    moot:
      lemma: wie
      tag: PWAV
      word: wie
    msafe: '1'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: wie
  - text: oede
    moot:
      lemma: öde
      tag: ADJD
      word: öde
    msafe: '0'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: oede
  - text: '!'
    errid: ec
    exlex: '!'
    moot:
      lemma: '!'
      tag: $.
      word: '!'
    msafe: '1'
    xlit:
      isLatin1: '1'
      isLatinExt: '1'
      latin1Text: '!'

AUTHOR

Bryan Jurish <moocow@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2010-2019 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.24.1 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 506:

Non-ASCII character seen before =encoding in 'öde'. Assuming CP1252