Code like this solved a similar problem for me:
sub ACTION_test {
my $self = shift;
my $ok = $self->SUPER::ACTION_test;
if ($ok) {
$ok = do { ... my code to run *additional* tests ... };
}
return $ok;
}
But perhaps that that is not applicable in your case? Otherwise, I
think your depends hash is a fine solution.
Chris
On Jan 28, 2008, at 11:56 PM, Michael G Schwern wrote:
In the process of overriding an ACTION I've noticed two things:
1) The process, while simple, is very sparsely documented.
2) The most common mistake is forgetting about dependent actions
when you do a complete override, and that's not documented anywhere.
#1 is a documentation issue. #2 is an interface issue. For
example, let's say I want to completely override how tests work.
So I might write...
sub ACTION_test {
my $self = shift;
my $ok = ...my code to run tests...
return $ok;
}
I forgot to call $self->depends_on('code'). How would I know to do
this? More importantly, how do I know what the test action depends
on? And how do I know that's still going to be the right thing in
the next version?
Most of the time the person overriding an ACTION doesn't want to
change it's dependencies. Or if so just wants to add to it. So
it's monkey code to have them worry about that.
To resolve this, I propose we change the procedure from calling
$self->depends_on(@dependents) to $self->depends_for
($current_action). For example...
sub ACTION_test {
my $self = shift;
$self->depends_for('test');
my $ok = ...my code to run tests...
return $ok;
}
The dependencies for each action can live in a simple hash structure:
testdb => ['test'],
testcover => ['code', 'test'],
depends_for() is simply:
sub depends_for {
my($self, $action) = @_;
my @dependencies = @{$dependencies{$action} || []};
$self->depends_on(@dependencies);
}
Some dependencies are more complicated, like testcover depends on
code, then does some work, then "depends on" test when in reality
it doesn't really depend on the test action but overrides its
behavior. testdb is similar. Either way, complex cases like this
can still be handled, depends_for() is a convenience, not a
replacement for depends_on().
--
125. Two drink limit does not mean two kinds of drinks.
-- The 213 Things Skippy Is No Longer Allowed To Do In The U.S.
Army
http://skippyslist.com/?page_id=3