in reply to Allowing the over riding of a program's design

You can use callback (I hope I haven't twisted them into somthing else) that will do what you need. I use them in OOP and assign a default sub via a method, that is I create a method to return the default sub routine (action/code) if one isn't passed into the mehtod that uses the sub.
Here is the method that returns the default code (sub):
sub default_code { my ($self,$extra) = @_; my $sub = sub { my ($extra,$optional,$optional) = @_; # do something }; return $sub; }
The method that might use this sub allows for a callback or overriding sub that is passed in via the method options.
$object->display( { my_code => sub { my ($hashref) = shift; foreach (keys %$hashref) { # more code } }; } );
Then in the display method
sub display { my ($self,$args) = @_; # $args->{'my_code'} has our "custom code" # here is where we determine which one to use my $action = $args->{'my_code'} || $self->default_code; $action->($args); }
I don't know if this good style or not, but it has been working well for what I needed.

Replies are listed 'Best First'.
Re: Re: Allowing the over riding of a program's design
by skazat (Chaplain) on Feb 07, 2002 at 19:16 UTC

    If anything, this is an interesting snippet of code use. I bet I could allow people to add the overriding code via a form in the admin screens.... That in itself might not be good style as well, but a good idea at least to throw in the pot.

    -justin simoni
    !skazat!