Tie::Simple(3)
β¨ NAME β¨ β Tie::Simple(3) π
Tie::Simple β variable ties made easier: much, much, much easier... π«Ά
π VERSION π
version 1.04 β that's the one, bestie. β¨
πΈ SYNOPSIS πΈ
Ok so here's the whole βlook how easy this isβ lineup. You use Tie::Simple;, then you tie whatever variable type you want and hand over your name/CODE pairs:
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 { ... };
π DESCRIPTION π
This module adds the ability to quickly create new types of tie objects without creating a complete class. It does that in a way that tries to make the programmerβs life easier when it comes to single-use ties that the author finds themself wanting to use from time to time. π«Ά
The Tie::Simple package is actually a front-end to other classes that really do all the work once tied, but this package does the dwimming to automatically figure out what youβre trying to do. β¨
The author tried to make this as intuitive as possible and dependent on other bits of Perl where possible, to minimize the need for documentation and make this extra, extra spiffy. π
π¦ SIMPLE TYING π¦
To set up your quick tie, simply start with the typical tie statement on the variable youβre tying. You should always tie to the Tie::Simple package and not directly to the other packages included with this module, because those are only present as helpers β even though they are really the tie classes. π
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:
- The variable to be tied.
- The string
'Tie::Simple'. - A scalar value (hereafter called the βlocal dataβ).
- A list of
name/CODEpairs.
At this point, youβll need to have some understanding of tying before you can continue. The author suggests 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. π
π₯ TIES CAN BE SIMPLER STILL π₯
The synopsis above shows the typical subroutines you could define. The author left out the UNTIE and DESTROY methods, but you may define these if you need them β just be sure to read the perltie documentation on possible caveats. π
β οΈ Caveat corner, bestie:UNTIEandDESTROYare allowed, but theperltiedocs have the possible-caveats tea. Read before you ship it. β
However, the SYNOPSIS is way more complete than you probably need to be in most cases. This is because Tie::Simple does its best to make use of some of the handy Perl built-ins that help with creating tie packages. β¨
π SCALARS π
If you are creating a scalar tie, then you can assume all the benefits of being a Tie::Scalar. π
π ARRAYS π
If you are creating an array tie, then you may assume all the benefits of being a Tie::Array. π¦
π HASHES π
If you are creating a hash tie, then you may assume all the benefits of being a Tie::Hash. πΈ
π HANDLES π
If you are creating a handle tie, then you may assume all the benefits of being a Tie::Handle. π
π TO DO π
ngl, it sure would be nice if you could declare custom @ISA lists, wouldnβt it? The author would like to add such a feature, but coming up with some custom SUPER:: dispatch code or generating new anonymous packages are the only ways they can think to do it. They donβt really have time to add such a feature just now. π
π SEE ALSO π
perltieTie::ScalarTie::ArrayTie::HashTie::Handle
π AUTHOR π
Andrew Sterling Hanenkamp <hanenkamp@cpan.org> π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2015 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Thatβs a wrap, bestie β this page is tied to perl v5.42.0, dated 2015-11-29, and filed under Tie::Simple(3). π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Tie-Simple 1.04-bp160.1.12 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms