NAME
DiaColloDB::EnumFile::Tied - diachronic collocation db: symbol<->integer enum: tied interface
PACKAGES
- DiaColloDB::EnumFile::Tied
-
Top-level dummy package.
- DiaColloDB::EnumFile::TiedArray
-
Low-level Tie::Array subclass for representing a integer->symbol mapping as a tied array.
- DiaColloDB::EnumFile::TiedHash
-
Low-level Tie::Hash subclass for representing symbol->integer mapping as a tied hash.
SYNOPSIS
##========================================================================
## PRELIMINARIES
use DiaColloDB::EnumFile::Tied;
##========================================================================
## Tied interface
$enum = $CLASS->tienew(%opts,class=>$enumFileClass); ##-- utility wrapper
(\@id2sym,\%sym2id) = $CLASS->tiepair(%opts);
(\@id2sym,\%sym2id) = $CLASS->tiepair($enum);
(\@id2sym,\%sym2id) = $enum->tiepair();
$class = $CLASS_OR_OBJECT->tieArrayClass();
$class = $CLASS_OR_OBJECT->tieHashClass();
##========================================================================
## API: DiaColloDB::EnumFile::TiedArray
##-- mandatory methods
$tied = TIEARRAY($class, $tieClass, %opts, class=>$enumFileClass);
$val = $tied->FETCH($index);
$count = $tied->FETCHSIZE();
$val = $tied->STORE($index,$val);
$count = $tied->STORESIZE($count);
$bool = $tied->EXISTS($index);
undef = $tied->DELETE($index);
##-- optional methods
undef = $tied->CLEAR();
##========================================================================
## API: DiaColloDB::EnumFile::TiedHash
$val = $tied->STORE($key, $value);
$val = $tied->FETCH($key);
$key = $tied->FIRSTKEY();
$key = $tied->NEXTKEY($lastkey);
$bool = $tied->EXISTS($key);
undef = $tied->DELETE($key);
undef = $tied->CLEAR();
$scalar = $tied->SCALAR();
DESCRIPTION
DiaColloDB::EnumFile::Tied provides a tie() interface for treating DiaColloDB::EnumFile objects (and subclasses thereof) as a pair (\@id2sym,\%sym2id), where \@id2sym is a tied ARRAY-ref mapping IDs to symbols via DiaColloDB::EnumFile::i2s() and \%sym2id is a tied HASH-ref mapping symbols to IDs via DiaColloDB::EnumFile::s2i(). The tied references are suitable for use by other code expecting enums as in-memory perl datastructures, e.g. MUDL::Enum as used by the DocClassify module.
Tied Interface
- tienew
-
$enum = $CLASS->tienew(%opts,class=>$enumFileClass); $enum = $CLASS->tienew($enum);
returns $enum if specified, otherwise a new DiaColloDB::EnumFile object for %opts.
- tiepair
-
(\@id2sym,\%sym2id) = $CLASS->tiepair(%opts); (\@id2sym,\%sym2id) = $CLASS->tiepair($enum); (\@id2sym,\%sym2id) = $enum->tiepair();
Returns pair of tied objects suitable for simulating e.g. MUDL::Enum. %opts: passed to $CLASS->tienew(). Ties objects using $enum->tieArrayClass() rsp. $enum->tieHashClass().
- tieArrayClass
-
$class = $CLASS_OR_OBJECT->tieArrayClass()
Returns class for tied arrays to be returned by tiepair() method; default just returns "DiaColloDB::EnumFile::TiedArray".
- tieHashClass
-
$class = $CLASS_OR_OBJECT->tieHashClass()
Returns class for tied arrays to be returned by tiepair() method; default just returns "DiaColloDB::EnumFile::TiedHash".
DiaColloDB::EnumFile::TiedArray
- TIEARRAY
-
$tied = tie(@array, $tieClass, $enum); $tied = tie(@array, $tieClass, %opts); $tied = DiaColloDB::EnumFile::TiedArray->TIEARRAY($tieClass, %opts, class=>$enumFileClass); $tied = DiaColloDB::EnumFile::TiedArray->TIEARRAY($tieClass, $enum);
%opts as for DiaColloDB::EnumFile::tienew(); returns $tied = \$enum.
- FETCH
-
$val = $tied->FETCH($index);
wraps i2s().
- FETCHSIZE
-
$count = $tied->FETCHSIZE();
like scalar(@array)
- STORE
-
$val = $tied->STORE($index,$val);
store a value.
- STORESIZE
-
$count = $tied->STORESIZE($count);
not quite safe
- EXISTS
-
$bool = $tied->EXISTS($index);
check for existence.
- DELETE
-
undef = $tied->DELETE($index);
not properly supported; just deletes from in-memory cache
- CLEAR
-
undef = $tied->CLEAR();
clears the enum.
DiaColloDB::EnumFile::TiedHash
- TIEHASH
-
$tied = tie(%hash, $tieClass, $enum) $tied = tie(%hash, $tieClass, %opts) $tied = DiaColloDB::EnumFile::TiedHash->TIEHASH($tieClass, %opts, class=>$enumFileClass) $tied = DiaColloDB::EnumFile::TiedHash->TIEHASH($tieClass, $enum)
%opts as for DiaColloDB::EnumFile::tienew(). Returns $tied = \$enum.
- STORE
-
$val = $tied->STORE($key, $value);
Stores value.
- FETCH
-
$val = $tied->FETCH($key);
Fetches ID for symbol $key.
- FIRSTKEY
-
$key = $tied->FIRSTKEY();
get first key (for iteration).
- NEXTKEY
-
$key = $tied->NEXTKEY($lastkey);
get next key (for iteration); only works for enums without index-gaps.
- EXISTS
-
$bool = $tied->EXISTS($key);
check for symbol existence.
- DELETE
-
undef = $tied->DELETE($key);
delete a symbol. not properly supported; just deletes from in-memory cache
- CLEAR
-
undef = $tied->CLEAR();
clears the enum.
- SCALAR
-
$scalar = $tied->SCALAR();
returns key count.
AUTHOR
Bryan Jurish <moocow@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2015-2020 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.14.2 or, at your option, any later version of Perl 5 you may have available.