in reply to Installing chained methods

Hook::WrapSub? Hook::PrePostCall? Hook::LexWrap? One of these will probably suit your tastes.

Makeshifts last the longest.

  • Comment on Re: Installing chained methods (Hook::*?)

Replies are listed 'Best First'.
Re: Re: Installing chained methods
by diotalevi (Canon) on Apr 21, 2003 at 03:42 UTC

    Nothing in the Hook:: class namespace does the right thing here (including Class::Hook). Thank you though. All the Hook:: modules assume that the method already exists and I'm looking at it from the other direction - initially the method doesn't exist and the code just installs it somewhat like Exporter.

    Oh well - absent any good suggestions (after waiting a while) I'll just write the darn thing and upload it. Thank you for suggesting Hook:: though - that search keyword didn't occur to me.

      Aha, I see. Maybe like so?
      use Hook::WrapSubs; do { no strict 'refs'; *{"GreenPartyDB::Database::${table}::${hook}"} = sub {}; } unless UNIVERSAL::can("GreenPartyDB::Database::${table}", $hook) wrap_subs( "GreenPartyDB::Database::${table}::${hook}", UNIVERSAL::can(__PACKAGE__."::${prefix}", $hook), );
      Note that using UNIVERSAL::can() will respect inherited methods, which is not unlikely to be better than what you started out with (or may be not, of course - your call).

      Makeshifts last the longest.

        What do you think of calling it 'Class::AppendMethods'?