Hub::Knots::TiedObject - Tied object


hub-standard documentation  | view source Contained in the hub-standard distribution.

Index


NAME

Top

Hub::Knots::TiedObject - Tied object

SYNOPSIS

Top

In your class:

  package __Package_Name__;
  use Hub qw(:lib);
  sub new {
    my $self = shift;
    my $class = ref( $self ) || $self;
    my $obj = bless {}, $class;
    tie %$obj, 'Hub::Knots::TiedObject', '__Tie_Package__';
    return $obj;
  }#new







DESCRIPTION

Top

Perl5 does not let one implement tie methods for a normal blessed package. To get around this, the above constructor ties the blessed reference to this package, providing '__Tie_Package__' as the package which should implement the tie methods.

Intention

To transparently provide `tie' methods inline with an existing class. For example, one may have a User class which supports several methods, such as `print', and we wish to update the database on the fly...

    my $user = new User( $conn, 'mary', 'alzxjVT8kR.aU' );
    $user->{'lname'} = "Lopez";
    $user->print();

Implementation

TiedObject simply provides two hashes for the object: `public' and `private'. When data members are accessed, the 'public' hash is acted upon. If the index begins with an asterisk (*) then the private hash is used. The only values currently in the private hash are:

    $self->{'*tied'};         # Points to the reference returned by tie-ing 
                              # '__Tie_Package__' to the public hash.

    $self->{'*public'};       # Points to the public hash













INTERNAL METHODS

Top

_key

Determine which key (public or private) to use

TIEHASH

Tie interface method


 Usage: TIEHASH 'Hub::Knots::TiedObject', $PACKAGE




FETCH

Return a value

STORE

Store a value

DELETE

Remove a value

CLEAR

Remove all public values

EXISTS

Boolean test for value

FIRSTKEY

Tie interface method

NEXTKEY

Tie interface method

SCALAR

Scalar representation

UNTIE

Tie interface method

AUTHOR

Top

Ryan Gies (ryangies@livesite.net)

COPYRIGHT

Top

UPDATED

Top

08/02/2007


hub-standard documentation  | view source Contained in the hub-standard distribution.