http://www.perlmonks.org?node_id=354995


in reply to Functional Inside Out Closure Objects

I, like many people (See the number of Class::* modules on CPAN), have sought to make oop easier in perl.

Personally, I never really thought of OOPerl as hard, ugly yes, primative maybe, clobbered on, for sure, but not really all that hard. :P

It is my understanding that when closures are used that the different version of a closure share the same code but just use a different set of lexicals. So I think that the overhead for an individual object should just be the set of lexicals plus the references to the CODE objects. Is this a correct understanding of how closures work?

This is pretty much my understand of closures as well. Although I cannot say for sure that it is correct :)

My second question about overhead is the use of the "goto" in the methods

You could likely get rid of the goto if you wanted to. Instead of evaling your code like this:

# create method my $eval = "sub $class\:\:$name { goto \$hash{\$_[0]}}\n"; eval $eval;
You could just do some symbol table mangling like this:
*{"${class}::$name"} = $ref;
The result should be the same, but no goto.

-stvn