Movatterモバイル変換


[0]ホーム

URL:


Tie::Array
(source,CPAN)
version 1.07
You are viewing the version of this documentation from Perl 5.40.0.View the latest version

CONTENTS

#NAME

Tie::Array - base class for tied arrays

#SYNOPSIS

package Tie::NewArray;use Tie::Array;@ISA = ('Tie::Array');# mandatory methodssub TIEARRAY { ... }sub FETCH { ... }sub FETCHSIZE { ... }sub STORE { ... }       # mandatory if elements writeablesub STORESIZE { ... }   # mandatory if elements can be added/deletedsub EXISTS { ... }      # mandatory if exists() expected to worksub DELETE { ... }      # mandatory if delete() expected to work# optional methods - for efficiencysub CLEAR { ... }sub PUSH { ... }sub POP { ... }sub SHIFT { ... }sub UNSHIFT { ... }sub SPLICE { ... }sub EXTEND { ... }sub DESTROY { ... }package Tie::NewStdArray;use Tie::Array;@ISA = ('Tie::StdArray');# all methods provided by defaultpackage main;$object = tie @somearray,'Tie::NewArray';$object = tie @somearray,'Tie::StdArray';$object = tie @somearray,'Tie::NewStdArray';

#DESCRIPTION

This module provides methods for array-tying classes. Seeperltie for a list of the functions required in order to tie an array to a package. The basicTie::Array package provides stubDESTROY, andEXTEND methods that do nothing, stubDELETE andEXISTS methods that croak() if the delete() or exists() builtins are ever called on the tied array, and implementations ofPUSH,POP,SHIFT,UNSHIFT,SPLICE andCLEAR in terms of basicFETCH,STORE,FETCHSIZE,STORESIZE.

TheTie::StdArray package provides efficient methods required for tied arrays which are implemented as blessed references to an "inner" perl array. It inherits fromTie::Array, and should cause tied arrays to behave exactly like standard arrays, allowing for selective overloading of methods.

For developers wishing to write their own tied arrays, the required methods are briefly defined below. See theperltie section for more detailed descriptive, as well as example code:

#TIEARRAY classname, LIST

The class method is invoked by the commandtie @array, classname. Associates an array instance with the specified class.LIST would represent additional arguments (along the lines ofAnyDBM_File and compatriots) needed to complete the association. The method should return an object of a class which provides the methods below.

#STORE this, index, value

Store datumvalue intoindex for the tied array associated with objectthis. If this makes the array larger then class's mapping ofundef should be returned for new positions.

#FETCH this, index

Retrieve the datum inindex for the tied array associated with objectthis.

#FETCHSIZE this

Returns the total number of items in the tied array associated with objectthis. (Equivalent toscalar(@array)).

#STORESIZE this, count

Sets the total number of items in the tied array associated with objectthis to becount. If this makes the array larger then class's mapping ofundef should be returned for new positions. If the array becomes smaller then entries beyond count should be deleted.

#EXTEND this, count

Informative call that array is likely to grow to havecount entries. Can be used to optimize allocation. This method need do nothing.

#EXISTS this, key

Verify that the element at indexkey exists in the tied arraythis.

TheTie::Array implementation is a stub that simply croaks.

#DELETE this, key

Delete the element at indexkey from the tied arraythis.

TheTie::Array implementation is a stub that simply croaks.

#CLEAR this

Clear (remove, delete, ...) all values from the tied array associated with objectthis.

#DESTROY this

Normal object destructor method.

#PUSH this, LIST

Append elements of LIST to the array.

#POP this

Remove last element of the array and return it.

#SHIFT this

Remove the first element of the array (shifting other elements down) and return it.

#UNSHIFT this, LIST

Insert LIST elements at the beginning of the array, moving existing elements up to make room.

#SPLICE this, offset, length, LIST

Perform the equivalent ofsplice on the array.

offset is optional and defaults to zero, negative values count back from the end of the array.

length is optional and defaults to rest of the array.

LIST may be empty.

Returns a list of the originallength elements atoffset.

#CAVEATS

There is no support at present for tied @ISA. There is a potential conflict between magic entries needed to notice setting of @ISA, and those needed to implement 'tie'.

#AUTHOR

Nick Ing-Simmons <nik@tiuk.ti.com>

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp