LPM: Strict variable checking in classes?

Rich Bowen rbowen at rcbowen.com
Thu Mar 29 08:35:46 CST 2001


Resend - nonmember submission

-------- Original Message --------

From: Matt Cashner <eek at eekeek.org>
To: Perl Geeks <lexington-pm-list at happyfunball.pm.org>
Subject: Re: LPM: Strict variable checking in classes?

On Wed, 28 Mar 2001, David Hempy wrote:

> However, the laid-back approach of hash lookups will happily let me print a 
> useless $this->{coutn} after incrementing $this->{count} a few thousand 
> times.  Tracking down typos like that can be a real pain.  (And a 
> shuddering C programmer now beams...)

use vars qw($AUTOLOAD);
sub AUTOLOAD {
	my $self = shift;
    my ($method, $return);
    ($method = $AUTOLOAD) = ~s/.*:://;
    if($self->{$method}) {
        if(@_) {
            $self->{$method} = shift;
        }
        return $self->{$method};
    } else {
        warn "there is no $method attribute of this object, bingo.";
        return undef;
    }
}
 
provided i typed that in correctly, that should work for you. if you
need an explanation of anything just ask :)

and blessed has one syllable in my vernacular :) 
    
--------
Matt Cashner
Web Applications Developer
The Creative Group (http://www.cre8tivegroup.com)
eek at eekeek.org | Codito, ergo sum



More information about the Lexington-pm mailing list