use Tie::Simple;
tie $scalar, 'Tie::Simple', $data,
FETCH => sub { ... },
STORE => sub { ... };
tie @array, 'Tie::Simple', $data,
FETCH => sub { ... },
STORE => sub { ... },
FETCHSIZE => sub { ... },
STORESIZE => sub { ... },
EXTEND => sub { ... },
EXISTS => sub { ... },
DELETE => sub { ... },
CLEAR => sub { ... },
PUSH => sub { ... },
POP => sub { ... },
SHIFT => sub { ... },
UNSHIFT => sub { ... },
SPLICE => sub { ... };
tie %hash, 'Tie::Simple', $data,
FETCH => sub { ... },
STORE => sub { ... },
DELETE => sub { ... },
CLEAR => sub { ... },
EXISTS => sub { ... },
FIRSTKEY => sub { ... },
NEXTKEY => sub { ... };
tie *HANDLE, 'Tie::Simple', $data,
WRITE => sub { ... },
PRINT => sub { ... },
PRINTF => sub { ... },
READ => sub { ... },
READLINE => sub { ... },
GETC => sub { ... },
CLOSE => sub { ... };
The "Tie::Simple" package is actually a front-end to other classes which really do all the work once tied, but this package does the dwimming to automatically figure out what you're trying to do.
I've tried to make this as intuitive as possible and dependent on other bits of Perl where I can to minimize the need for documentation and to make this extra, extra spiffy.
The type of tie depends upon the type of the first argument given to tie. This should be rather obvious from the ``SYNOPSIS'' above. Therefore, the arguments are:
At this point, you'll need to have some understanding of tying before you can continue. I suggest looking through perltie.
As you will note in the perltie documentation, every tie package defines functions whose first argument is called "this". The third argument, local data, will take the place of "this" in all the subroutine calls you define in the name/CODE pair list. Each name should be the name of the function that would be defined for the appropriate tie-type if you were to do a full-blown package definition. The subroutine matched to that name will take the exact arguments specified in the perltie documentation, but instead of "this" it will be given the local data scalar value you set (which could even be "undef" if you don't need it).
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.