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};
}