perl-5.38.0
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, or TIEHASH). Typically these are arguments such as might be passed to the dbm_open(3) function of C. The object returned by the constructor is also returned by the tie function, which would be useful if you want to access other methods in CLASSNAME.

この関数は、変数を、その変数の実装を行なうクラスと結び付けます。 VARIABLE は、魔法をかける変数の名前です。 CLASSNAME は、正しい型のオブジェクトを実装するクラスの名前です。 他に引数があれば、そのクラスの適切なコンストラクタメソッドに渡されます (つまり TIESCALAR, TIEHANDLE, TIEARRAY, TIEHASH)。 通常、これらは、C の dbm_open(3) などの関数に渡す引数となります。 コンストラクタで返されるオブジェクトはまた tie 関数でも返されます; これは CLASSNAME の他のメソッドにアクセスしたいときに便利です。

Note that functions such as keys and values may return huge lists when used on large objects, like DBM files. You may prefer to use the each function to iterate over such. Example:

DBM ファイルのような大きなオブジェクトでは、keysvalues のような関数は、大きなリストを返す可能性があります。 そのような場合では、each 関数を使って繰り返しを行なった方が よいかもしれません。 例:

    # print out history file offsets
    use NDBM_File;
    tie(my %HIST, 'NDBM_File', '/usr/lib/news/history', 1, 0);
    while (my ($key,$val) = each %HIST) {
        print $key, ' = ', unpack('L', $val), "\n";
    }

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:

通常の配列を実装するクラスでは、次のようなメソッドを用意します:

    TIEARRAY classname, LIST
    FETCH this, key
    STORE this, key, value
    FETCHSIZE this
    STORESIZE this, count
    CLEAR this
    PUSH this, LIST
    POP this
    SHIFT this
    UNSHIFT this, LIST
    SPLICE this, offset, length, LIST
    EXTEND this, count
    DELETE this, key
    EXISTS this, key
    DESTROY this
    UNTIE this

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.

上記の全てのメソッドを実装する必要はありません。 perltie, Tie::Hash, Tie::Array, Tie::Scalar, Tie::Handle を参照してください。

Unlike dbmopen, the tie function will not use or require a module for you; you need to do that explicitly yourself. See DB_File or the Config module for interesting tie implementations.

dbmopen と違い、 tie 関数はモジュールを use したり require したりしません; 自分で明示的に行う必要があります。 tie の興味深い実装については DB_FileConfig モジュールを参照してください。

For further details see perltie, tied.

更なる詳細については perltietied を 参照してください。