Oops That namespace is taken. I'll think again. Suggestions welcome.
Quite often I find myself needing a simple check to see if a sub has already been called. This happens all the time and I hate coding this.
use Sub::Called 'already_called', 'not_called'; sub user { unless (already_called) { # only gets called once My::Fixtures::Users->load; } ... } sub schema { if ( not_called ) { # setup schema } else { return $schema; } }
Yeah, it was only five minutes to write and it's a minor, minor nit, but I hopefully won't have to worry about it again. It should be on the CPAN soon.
It checks the package and subroutine to determine if it's been called yet.
It's possibly my most trivial module. Flame away!
memoize('function', CALLBACK_ON_LOAD => sub{ My::Fixtures::Users->load });
This gives me an idea for the Ruby memoize library, actually...
Re:Memoize?
Ovid on 2008-07-22T15:29:32
I don't want to necessarily memoize these functions, so hooking into that doesn't seem right (though to be fair, it didn't occur to me, either).
Re:I can add this functionality to my module
Ovid on 2008-07-23T08:09:52
If you want to do that, it would be great and I can just delete mine. Thanks
:)