tie
- tie VARIABLE,CLASSNAME,LIST
This function binds a variable to a package class that will provide the implementation for the variable. VARIABLE is the name of the variable to be enchanted. CLASSNAME is the name of a class implementing objects of correct type. Any additional arguments are passed to the appropriate constructor method of the class (meaning
TIESCALAR
,TIEHANDLE
,TIEARRAY
, orTIEHASH
). Typically these are arguments such as might be passed to thedbm_open()
function of C. The object returned by the constructor is also returned by thetie
function, which would be useful if you want to access other methods in CLASSNAME.Note that functions such as
keys
andvalues
may return huge lists when used on large objects, like DBM files. You may prefer to use theeach
function to iterate over such. Example:A class implementing a hash should have the following methods:
- TIEHASH classname, LIST
- FETCH this, key
- STORE this, key, value
- DELETE this, key
- CLEAR this
- EXISTS this, key
- FIRSTKEY this
- NEXTKEY this, lastkey
- SCALAR this
- DESTROY this
- UNTIE this
A class implementing an ordinary array should have the following methods:
A class implementing a filehandle should have the following methods:
- TIEHANDLE classname, LIST
- READ this, scalar, length, offset
- READLINE this
- GETC this
- WRITE this, scalar, length, offset
- PRINT this, LIST
- PRINTF this, format, LIST
- BINMODE this
- EOF this
- FILENO this
- SEEK this, position, whence
- TELL this
- OPEN this, mode, LIST
- CLOSE this
- DESTROY this
- UNTIE this
A class implementing a scalar should have the following methods:
- TIESCALAR classname, LIST
- FETCH this,
- STORE this, value
- DESTROY this
- UNTIE this
Not all methods indicated above need be implemented. See perltie, Tie::Hash, Tie::Array, Tie::Scalar, and Tie::Handle.
Unlike
dbmopen
, thetie
function will notuse
orrequire
a module for you; you need to do that explicitly yourself. See DB_File or the Config module for interestingtie
implementations.For further details see perltie, tied VARIABLE.