I'd like to install one or a few methods into a given slot. If no method already exists in a given slot then my copy should be directly copied. If I need a second or more method to then I need to have a stub method call each of the real methods. While the actual code for this is pretty simple I think this far too messy for something in a database application and I don't want to force volunteer programmers to cope with this.

This is intended to be used in an application using the Alzabo OR mapping system and in this case I need to call both an auditing and versioning method when the pre_insert event occurs. For one method call I'd just copy *pkg::pre_insert = *auditing_pre_insert and leave it at that but since it isn't that trivial I don't feel comfortable doing this right in the application.

I'm hoping someone here knows of a nice module for this so I can use that instead. Suggestions?

if (*{"GreenPartyDB::Database::${table}::${hook}"}{CODE}) { my $old = *{"GreenPartyDB::Database::${table}::${hook}"}{CODE}; my $new = *{__PACKAGE__."::${prefix}${hook}"}{CODE} *{"GreenPartyDB::Database::${table}::${hook}"} = sub { $_[0]->$old( @_[ 1 .. $#_ ] ); $_[0]->$new( @_[ 1 .. $#_ ] ); }; } else { *{"GreenPartyDB::Database::${table}::${hook}"} = *{__PACKAGE__."::${prefix}${hook}"}{CODE}; }

In reply to Installing chained methods by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.