Without the lexical hash, it's not an inside-out object. What I left off was actually using the property hashes:
sub as_string {
my $self = shift;
return $name{ id $self } . " is " . $age{ id $self } . " year(s) o
+ld.";
}
I suppose there's some XS magic that could take a name and create a lexical in the right place, but I'm not an XS expert (yet) and I'm not sure I'd want to add that kind of dependency.
(Also, in your example those are barewords, so they really should be quoted.)
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|