Well, after seeing MJD do his 'Tips and Tricks' talk I was
somewhat inspired (I'd wanted to see it for quite a while).
So I tried this out:
package Whatever;
sub new {
my $class = shift;
my $arg2 = shift;
my $lexical;
return bless sub {
sub arg2 {
return $arg2;
}
1;
}, $class;
}
and it appeared to work. However, MJD pointed out that if
you instantiate the object twice it falls over (although
the closure gets a new pad the subs inside the anonsub
obviously -- in retrospect -- don't). Ah well. It would
have been nice syntax, but it didn't quite work for now
apparant reasons.
package main;
$n = Whatever->new( 'this' );
print $n->arg2();
Overall the conference is good -- I'm coming away with some
good ideas for talks, and picking up bits and pieces that
are interesting. Tonight I'm out with friends from
Montreal, so I should be reasonably hung over tomorrow. :-)
Just in: I've realized that these are actually natural singletons with no extra trickery required.