#!/usr/bin/perl package Goo::Object; ############################################################################### # Nigel Hamilton # # Copyright Nigel Hamilton 2002 # All Rights Reserved # # Author: Nigel Hamilton # Filename: Goo::Object.pm # Description: Super object that holds convenience methods. # All objects that inherit from this are hash-based. # # Date Change # ---------------------------------------------------------------------------- # 27/05/02 Version 1 - used for debugging # Added Clone method - needed for mod_perl persistent environment # 24/07/04 DataDumper was hanging around - removed in case of RAM consumption! # ############################################################################## use strict; ############################################################################## # # new - instantiate an object # ############################################################################## sub new { my ($class) = @_; my $this = {}; bless( $this, $class ); } ############################################################################## # # add_fields - add fields to this object # ############################################################################## sub add_fields { my ( $this, $fields ) = @_; if ( ref($fields) eq "HASH" ) { %$this = ( %$this, %$fields ); } } ############################################################################## # # has - return whether or not an attribute is defined for this object? # ############################################################################## sub has { my ( $this, $attribute ) = @_; return exists( $this->{$attribute} ); } ############################################################################## # # get_type - return the type of this object # ############################################################################## sub get_type { my ($this) = @_; return ref($this); } ############################################################################## # # to_string - return a string representation of this class # ############################################################################## sub to_string { my ($this) = @_; my $string = "[" . ref($this) . "]"; foreach my $key ( keys %$this ) { $string .= " $key = $this->{$key} |"; } return $string . "\n\n"; } ############################################################################## # # to_htmlstring - return a html representation of this class # ############################################################################## sub to_htmlstring { my ($this) = @_; my $string = "
| " . ref($this) . " | ||
| $key | $this->{$key} | |