use warnings;
use Scalar::Util qw( reftype);
-our $VERSION = '1.02_01';
+our $VERSION = '1.03';
require Exporter;
our @ISA = qw(Exporter);
fieldhashes @hashrefs;
### Create an idhash and register it for garbage collection
- use Hash::Util::FieldHash qw( idhash register);
+ use Hash::Util::FieldHash qw(idhash register);
idhash my %name;
- my $obj = \ do { my $o };
+ my $object = \ do { my $o };
# register the idhash for garbage collection with $object
- register( $obj, \ %name);
- # the following entry wil be deleted when $obj goes out of scope
- $name{ $obj} = 'John Doe';
+ register($object, \ %name);
+ # the following entry will be deleted when $object goes out of scope
+ $name{$object} = 'John Doe';
### Register an ordinary hash for garbage collection
- use Hash::Util::FieldHash qw( id register);
+ use Hash::Util::FieldHash qw(id register);
my %name;
- my $obj = \ do { my $o };
- # register the hash %name for garbage collection of $obj's id
- register $obj, \ %name;
- # the following entry wil be deleted when $obj goes out of scope
- $name{id $obj} = 'John Doe';
+ my $object = \ do { my $o };
+ # register the hash %name for garbage collection of $object's id
+ register $object, \ %name;
+ # the following entry will be deleted when $object goes out of scope
+ $name{id $object} = 'John Doe';
=head1 FUNCTIONS
=item idhashes
- idhashes \ my( %hash, %gnash, %trash)
+ idhashes \ my(%hash, %gnash, %trash)
idhashes \ @hashrefs
Creates many idhashes from its hashref arguments. Returns those
A word on terminology: I shall use the term I<field> for a scalar
piece of data that a class associates with an object. Other terms that
have been used for this concept are "object variable", "(object) property",
-"(object) attribute" and more. Especally "attribute" has some currency
+"(object) attribute" and more. Especially "attribute" has some currency
among Perl programmer, but that clashes with the C<attributes> pragma. The
term "field" also has some currency in this sense and doesn't seem
to conflict with other Perl terminology.
the piece of data pointed to by the reference.
In consequence, if two or more classes want to access an object they
-I<must> agree on the type of refrerence and also on the organization of
+I<must> agree on the type of reference and also on the organization of
data within the object body. Failure to agree on the type results in
immediate death when the wrong method tries to access an object. Failure
to agree on data organization may lead to one class trampling over the
all other objects, with its own data. This object may be called
the I<generic object> of the class.
-This works because field hashes respond to keys that are not refrences
+This works because field hashes respond to keys that are not references
like a normal hash would and use the string offered as the hash key.
Thus, if a method is called as a class method, the field hash is presented
with the class name instead of an object and blithely uses it as a key.
Further methods may be defined outside this block. There has to be
a DESTROY method and, for thread support, a CLONE method.
-When field hashes are used, the basic structure reamins the same.
+When field hashes are used, the basic structure remains the same.
Each lexical hash will be made a field hash. The call to C<refaddr>
can be omitted from the accessor methods. DESTROY and CLONE methods
are not necessary.
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless {}, $obj unless ref $obj;
$obj->{ first} = $first;
{
package Name_id;
- use Hash::Util::FieldHash qw( id);
+ use Hash::Util::FieldHash qw(id);
- my ( %first, %last);
+ my (%first, %last);
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless \ my $o, $obj unless ref $obj;
$first{ id $obj} = $first;
package Name_idhash;
use Hash::Util::FieldHash;
- Hash::Util::FieldHash::idhashes( \ my ( %first, %last));
+ Hash::Util::FieldHash::idhashes( \ my (%first, %last) );
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless \ my $o, $obj unless ref $obj;
$first{ $obj} = $first;
{
package Name_id_reg;
- use Hash::Util::FieldHash qw( id register);
+ use Hash::Util::FieldHash qw(id register);
- my ( %first, %last);
+ my (%first, %last);
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless \ my $o, $obj unless ref $obj;
- register( $obj, \ ( %first, %last));
+ register( $obj, \ (%first, %last) );
$first{ id $obj} = $first;
$last{ id $obj} = $last;
$obj;
{
package Name_idhash_reg;
- use Hash::Util::FieldHash qw( register);
+ use Hash::Util::FieldHash qw(register);
- Hash::Util::FieldHash::idhashes \ my ( %first, %last);
+ Hash::Util::FieldHash::idhashes \ my (%first, %last);
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless \ my $o, $obj unless ref $obj;
- register( $obj, \ ( %first, %last));
+ register( $obj, \ (%first, %last) );
$first{ $obj} = $first;
$last{ $obj} = $last;
$obj;
package Name_fieldhash;
use Hash::Util::FieldHash;
- Hash::Util::FieldHash::fieldhashes \ my ( %first, %last);
+ Hash::Util::FieldHash::fieldhashes \ my (%first, %last);
sub init {
my $obj = shift;
- my ( $first, $last) = @_;
+ my ($first, $last) = @_;
# create an object if called as class method
$obj = bless \ my $o, $obj unless ref $obj;
$first{ $obj} = $first;
# Verify that the base package works
- my $n = Name->init( qw( Albert Einstein));
+ my $n = Name->init(qw(Albert Einstein));
print $n->name, "\n";
print "\n";
# Create a named file handle (See definition below)
- my $nf = NamedFile->init( qw( /tmp/x Filomena File));
+ my $nf = NamedFile->init(qw(/tmp/x Filomena File));
# use as a file handle...
for ( 1 .. 3 ) {
my $l = <$nf>;
sub init {
my $obj = shift;
- my ( $file, $first, $last) = @_;
+ my ($file, $first, $last) = @_;
$obj = $obj->IO::File::new() unless ref $obj;
- $obj->open( $file) or die "Can't read '$file': $!";
- $obj->Name::init( $first, $last);
+ $obj->open($file) or die "Can't read '$file': $!";
+ $obj->Name::init($first, $last);
}
__END__
-
=head1 GUTS
To make C<Hash::Util::FieldHash> work, there were two changes to