| 1 | ## -*- Mode: CPerl -*- | ||
| 2 | ## | ||
| 3 | ## File: DTA::CAB::Format::XmlTokWrap.pm | ||
| 4 | ## Author: Bryan Jurish <moocow@cpan.org> | ||
| 5 | ## Description: Datum parser|formatter: XML (tokwrap) | ||
| 6 | |||
| 7 | package DTA::CAB::Format::XmlTokWrap; | ||
| 8 | use DTA::CAB::Format::XmlNative; | ||
| 9 | use DTA::CAB::Datum ':all'; | ||
| 10 | use XML::LibXML; | ||
| 11 | use IO::File; | ||
| 12 | use Carp; | ||
| 13 | use strict; | ||
| 14 | |||
| 15 | ##============================================================================== | ||
| 16 | ## Globals | ||
| 17 | ##============================================================================== | ||
| 18 | |||
| 19 | our @ISA = qw(DTA::CAB::Format::XmlNative); | ||
| 20 | |||
| 21 | BEGIN { | ||
| 22 | DTA::CAB::Format->registerFormat(name=>__PACKAGE__, filenameRegex=>qr/\.(?i:[tuws]\.?xml)$/); | ||
| 23 | DTA::CAB::Format->registerFormat(name=>__PACKAGE__, short=>$_) foreach (qw(txml t-xml twxml tw-xml)); | ||
| 24 | } | ||
| 25 | |||
| 26 | BEGIN { | ||
| 27 | *isa = \&UNIVERSAL::isa; | ||
| 28 | *can = \&UNIVERSAL::can; | ||
| 29 | } | ||
| 30 | |||
| 31 | ##============================================================================== | ||
| 32 | ## Constructors etc. | ||
| 33 | ##============================================================================== | ||
| 34 | |||
| 35 | ## $fmt = CLASS_OR_OBJ->new(%args) | ||
| 36 | ## + object structure: HASH ref | ||
| 37 | ## { | ||
| 38 | ## ##-- input: inherited | ||
| 39 | ## xdoc => $xdoc, ##-- XML::LibXML::Document | ||
| 40 | ## xprs => $xprs, ##-- XML::LibXML parser | ||
| 41 | ## | ||
| 42 | ## ##-- output: new | ||
| 43 | ## arrayEltKeys => \%akey2ekey, ##-- maps array keys to element keys for output | ||
| 44 | ## arrayImplicitKeys => \%akey2undef, ##-- pseudo-hash of array keys NOT mapped to explicit elements | ||
| 45 | ## key2xml => \%key2xml, ##-- maps keys to XML-safe names | ||
| 46 | ## xml2key => \%xml2key, ##-- maps xml keys to internal keys | ||
| 47 | ## ## | ||
| 48 | ## ##-- output: inherited | ||
| 49 | ## #encoding => $inputEncoding, ##-- default: UTF-8; applies to output only! | ||
| 50 | ## level => $level, ##-- output formatting level (default=0) | ||
| 51 | ## | ||
| 52 | ## ##-- common: safety | ||
| 53 | ## safe => $bool, ##-- if true (default), no "unsafe" token data will be generated (_xmlnod,etc.) | ||
| 54 | ## } | ||
| 55 | sub new { | ||
| 56 | my $that = shift; | ||
| 57 | my $fmt = $that->SUPER::new(@_); | ||
| 58 | |||
| 59 | $fmt->{key2xml}{text} = 't'; | ||
| 60 | $fmt->{xml2key}{t} = 'text'; | ||
| 61 | $fmt->{xml2key}{old} = 'text'; | ||
| 62 | |||
| 63 | $fmt->{key2xml}{doc} = 'sentences'; | ||
| 64 | $fmt->{xml2key}{sentences} = 'doc'; | ||
| 65 | |||
| 66 | $fmt->{parseXmlData} = 0 if (!exists($fmt->{parseXmlData})); ##-- ignore XML content | ||
| 67 | |||
| 68 | return $fmt; | ||
| 69 | } | ||
| 70 | |||
| 71 | ##============================================================================= | ||
| 72 | ## Methods: Output | ||
| 73 | ##============================================================================== | ||
| 74 | |||
| 75 | ##-------------------------------------------------------------- | ||
| 76 | ## Methods: Output: MIME & HTTP stuff | ||
| 77 | |||
| 78 | ## $short = $fmt->shortName() | ||
| 79 | ## + returns "official" short name for this format | ||
| 80 | ## + default just returns package suffix | ||
| 81 | sub shortName { | ||
| 82 | return 'txml'; | ||
| 83 | } | ||
| 84 | |||
| 85 | ## $ext = $fmt->defaultExtension() | ||
| 86 | ## + returns default filename extension for this format (default='.t.xml') | ||
| 87 | sub defaultExtension { return '.t.xml'; } | ||
| 88 | |||
| 89 | |||
| 90 | 1; ##-- be happy | ||
| 91 | |||
| 92 | __END__ |