Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday July 22, 2008
07:42 AM

Minor Annoyances to the CPAN

[ #36983 ]

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!

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Couldn't you add callback support to MJD's Memoize module? Add two options, CALLBACK_ON_LOAD and CALLBACK_IF_CACHED, or something:

    memoize('function', CALLBACK_ON_LOAD => sub{ My::Fixtures::Users->load });

    This gives me an idea for the Ruby memoize library, actually...

    • 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).

  • Hi Ovid,
    I could add the functionality you mentioned to my module...

    Cheers, Renee
    • If you want to do that, it would be great and I can just delete mine. Thanks :)