in reply to Pretending to be lisp: macros

There are lots of method-generator packages already available to do this kind of work for you. (I'm assuming that you're not stuck on the idea of using "pretend objects" and would be happy with a blessed object instance.)

You could do something like this with Class::MakeMethods easily enough:

package MyObject; use Class::MakeMethods::Autoload { 'new' => 'Template::Hash::new', '.*' => 'Template::Hash::scalar -self_closure', }; package main; my $object = MyObject->new(); my $new_func = $object->attrib(); $new_func->('value');

The Class::MakeMethods::Autoload statement says that we want to generate a constructor for "new", and for any other method name we want to construct a "scalar -self_closure" method.

The "-self_closure" flag informs Class::MakeMethods that you don't want a simple accessor -- you want to return a closure bound the the target object that will act as an accessor.