in reply to Allowing the over riding of a program's design
The method that might use this sub allows for a callback or overriding sub that is passed in via the method options.sub default_code { my ($self,$extra) = @_; my $sub = sub { my ($extra,$optional,$optional) = @_; # do something }; return $sub; }
Then in the display method$object->display( { my_code => sub { my ($hashref) = shift; foreach (keys %$hashref) { # more code } }; } );
I don't know if this good style or not, but it has been working well for what I needed.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); }
|
|---|
| 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 |