package slot; ## These constant may be changed but in accordance with the positions ## of the object created in the constuructors of class Tie::Hash::Create ## defined here and must hold for any class derived from Tie::Hash::Create ## too as e.g. Tie::Hash::KeysMask and Tie::Hash::Modulate. sub HREF() {1} # sub STATUS() {2} # reserved # sub DEFAULT(){3} # -> Modulate (subclass) # sub KM() {4} # -> KeysMask package Tie::Hash::Create; use 5.008007; our $VERSION = 0.01; use strict; no strict 'subs'; use Carp; require Tie::Hash; our @ISA = qw ( Tie::ExtraHash ); sub newHASH { my $class = shift; my %Baby = (); my $to = tie %Baby,$class,@_; $to->[slot::HREF] = \%Baby; } sub c {$_[0]->[slot::HREF]} # content 1; __END__ =head1 NAME Tie::Hash::Create - Extend Tie::ExtraHash, enables the tie-object to reflect the tied array =head1 SYNOPSIS package Tie::Hash::MyClass; ## Choose your name for MyClass ! use base Tie::Hash::Create; sub TIEHASH { my $class = shift; .......................... bless [{},undef,,,,],$class; # insert your stuff between the braces after "undef," } # Optionally redefine other methods of Tie::Hash S<------------ From within another file -----------> use Tie::Hash::MyClass; my $myHash = Tie::Hash::MyClass->newHASH(....); # behaves as if my $myHash; tie %$myHash,'Tie::Hash::MyClass',...; =head1 DESCRIPTION Look at sections L in L. Consider an object, say C<$tob> returned by tie. It is an array, primitive hash-operations are carried out on the first field of this array, that is $tob->[0], a reference to a hash. Surprisingly this hash reference and the reference to the tied hash variable are not the same. The purpose of this class is transmit to any derived class these features: 1. Store the reference to the real tied hash in the object C<$tob>. 2. Define an accessor C<$tob-Ec> to this hash. 3. Provide an operation C which manages a tie but returns a reference to the real tied hash. This way the real hash-variable which appear as the first argument of C is omitted. Instead C returns an anonymous reference to this hash-object. On the top of this file the package 'slot' defines a slot-name C which identify an index positions of an object. A derived class could also define its own slot names. The choice of the index does not matter, however if two sources of code could not be reused in one class as each one stores data of different matters onto the same place, then it is easy to change one name-value assignment in package 'slot'. Of course the structure of an object created by the constructor must meet such a change, this applies for any derived class too. =head2 OPERATORS =over 4 =item =over 8 =item Constructor TIEHASH inherited from superclass C. Note that the object returned by TIEHASH, the same as returned by C is different from the reference to the tied hash. =item newHASH Calls the constructor TIEHASH, however returns the reference identifying the tied Hash. =item c (content operator) Assume C<$tob> is an object of C which is a subclass of C and %H is the tied hash, so that C<$tob = tied %H>. Then C<$tob-Ec> evaluates to C<\%H>. =back =back =head1 SEE ALSO A Sample class derived from C is L. =head1 PREREQUISITES This module requires these other modules and libraries: C, =head1 AUTHOR Josef SchEnbrunner Ej.schoenbrunner@onemail.atE =head1 COPYRIGHT AND LICENSE Copyright (c) 2005 by Josef SchEnbrunner This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. =cut