in reply to trouble with evaluate

Basically, it sounds like you’re asking for a slight twist on “accessors.”   A Perl object is basically just a hash.   You can, therefore, obtain values from it that way.   (And yes, as you plan to do, “the object itself” should be the one that knows how to do this, and who checks for incorrect or nonsensical requests.)

Lately, I’ve gotten into the habit of putting “variables like these” into a separate hash, which is part of the object instance and with a name like, say, localvars.   These (and only these) are the values which are supposed to be accessible to routines like the ones you describe, and, since they’re now neatly in just one place, it’s easy to check them (and to Data::Dumper dump them).   It makes it really obvious that “you’re not supposed to just be grabbin’ any-old-key ... only one of these.”   And it’s easy to (Carp) confess if the name is wrong.

$self->{'localvars'}->{$var_name} ...

Replies are listed 'Best First'.
Re^2: trouble with evaluate
by JavaFan (Canon) on Apr 09, 2011 at 00:53 UTC
    A Perl object is basically just a hash.
    No, it's not. A Perl object is a reference that's blessed into a package. A hash isn't a reference. And while it's true many Perl objects are hashreferences, that's not the only way to create an object.