#!/usr/bin/perl # # Core object. Really just a dummy DESTROY so we can always call # SUPER::DESTROY. # - Cameron Simpson 21jul97 # =head1 NAME cs::Object - root class for objects =head1 SYNOPSIS use cs::Object; @ISA=(cs::Object); =head1 DESCRIPTION The B module provided a few common methods for most objects. =cut use strict qw(vars); ##BEGIN { use cs::DEBUG; cs::DEBUG::using(__FILE__); } package cs::Object; @cs::Object::ISA=(); =head1 GENERAL FUNCTIONS =over 4 =item reTIEHASH(I,I,I,I...) Tie the hash referenced by I to the specified I, passing the I to the B call. If the optional parameter I is B<1>, store the original contents of the hash in the tied object. =cut # ([preserve,]hashref,class[,TIEHASH-args]) sub reTIEHASH { {my(@c)=caller;warn "reTIEHASH(@_) from [@c]";} my($preserve)=($_[0] =~ /^[01]$/ ? shift(@_) : 1 ); my($phash,$impl)=(shift,shift); my %tmp; if ($preserve) { # copy the contents for my $key (keys %$phash) { $tmp{$key}=$phash->{$key}; } } tie(%$phash,$impl,@_) || die "tie($phash,$impl,@_) fails"; if (! defined $preserve) # ignore {} elsif ($preserve) # overwrite { # put the contents back for my $key (keys %tmp) { $phash->{$key}=$tmp{$key}; } } else # supply if missing - a bit dubious { for my $key (keys %tmp) { $phash->{$key}=$tmp{$key} if ! exists $phash->{$key}; } } } =back =cut sub DESTROY {} =head1 OBJECT METHODS =over 4 =item GetSet(I,I) If the optional parameter I is supplied, set the specified I of the object to I. Otherwise return the current value of I or B if it does not exist. =cut sub GetSet($$;$) { my($this,$field,$value)=@_; if (@_ > 2) { $this->{$field}=$value; } else { if (! exists $this->{$field}) { ## my@c=caller;warn "no $field in $this\n\tfrom [@c]\n\t"; return undef; } $this->{$field}; } } =back =head1 AUTHOR Cameron Simpson 21jul1997 =cut 1;