GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Tie::Simple(3) User Contributed Perl Documentation Tie::Simple(3)

Tie::Simple - Variable ties made easier: much, much, much easier...

version 1.04

  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 { ... };

This module adds the ability to quickly create new types of tie objects without creating a complete class. It does so in such a way as to try and make the programmers life easier when it comes to single-use ties that I find myself wanting to use from time-to-time.

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.

To setup 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 as 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:

1.
The variable to be tied.
2.
The string 'Tie::Simple'.
3.
A scalar value (hereafter called the "local data").
4.
A list of name/CODE pairs.

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).

The synopsis above shows the typical subroutines you could define. (I left out the "UNTIE" and "DESTROY" methods, but you may define these if you need them, but be sure to read the perltie documentation on possible caveats.) However, the "SYNOPSIS" is way more complete then you probably need to be in most cases. This is because "Tie::Simple" does it's best to make use of some of the handy Perl built-ins which help with creating tie packages.

If you are creating a scalar tie, then you can assume all the benefits of being a Tie::Scalar.

If you are creating an array tie, then you may assume all the benefits of being a Tie::Array.

If you are creating a hash tie, then you may assume all the benefits of being a Tie::Hash.

If you are creating a handle tie, then you may assume all the benefits of being a Tie::Handle.

It sure would be nice if you could declare custom @ISA lists, wouldn't it? I'd like to add such a feature, but coming up with some custom "SUPER::" dispatch code or generating new "anonymous" packages are the only ways I can think to do it. I don't really have time to add such a feature just now.

perltie, Tie::Scalar, Tie::Array, Tie::Hash, Tie::Handle

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

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.

2015-11-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.