in reply to Re: Creating stub methods
in thread Creating stub methods

Actually, I think the "use subs" declaration solves the problem I was looking at, though I kind of like your "subs::i" idea. And you're right that it would be nice if CGI.pm provided a "can" method, but so many people use UNIVERSAL::can() directly that I think simply predeclaring the subs would be easier.

Update: What I think is really nifty about the subs pragma is the line:

*{"${callpack}::$sym"} = \&{"${callpack}::$sym"};

We create the slot in the typeglob, but assign an undefined value. $module->can($method) works because we have the slot, but AUTOLOAD still gets called because there is no actual subroutine or method there. Nifty!

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^3: Creating stub methods
by Aristotle (Chancellor) on Dec 30, 2003 at 08:45 UTC
    In fact it's not undefined in the full sense of the word. If you take a reference to a named sub which isn't yet defined, that reference magically becomes defined and valid as soon as that sub is defined. Observe:
    $_ = \&x; *x = sub { print "Oh my\n" }; $_->();
    This does print "Oh my". Perl is devious like that.

    Makeshifts last the longest.