Subject: | Add can_action to check for defined actions |
I'm creating a subclass of Module::Build for some automating testing.
Parts of this testing involves special ./Build targets depending on
certain situations and my build script checks for certain targets. I
wanted a method to check it a target is defined and figured it should be
in Base.pm. I want to shield the higher-level users from knowing about
the implementation details of Module::Build so they don't have to know
the real method name as long as they know the action name.
I added a method called can_action, but it could be called something else.
Index: lib/Module/Build/Base.pm
===================================================================
--- lib/Module/Build/Base.pm (revision 12711)
+++ lib/Module/Build/Base.pm (working copy)
@@ -1585,11 +1585,17 @@
return if $self->{_completed_actions}{$action}++;
local $self->{action} = $action;
- my $method = "ACTION_$action";
- die "No action '$action' defined, try running the 'help' action.\n"
unless $self->can($method);
+ my $method = $self->can_action( $action );
+ die "No action '$action' defined, try running the 'help' action.\n"
unless $method;
return $self->$method();
}
+sub can_action {
+ my ($self, $action) = @_;
+
+ return $self->can( "ACTION_$action" );
+}
+
# cuts the user-specified options out of the command-line args
sub cull_options {
my $self = shift;
Index: lib/Module/Build/API.pod
===================================================================
--- lib/Module/Build/API.pod (revision 12711)
+++ lib/Module/Build/API.pod (working copy)
@@ -959,6 +959,13 @@
Returns a hash reference indicating the C<build_requires>
prerequisites that were passed to the C<new()> method.
+=item can_action( $action )
+
+Returns a reference to the method that defines C<$action>, or false
+otherwise. This is handy for actions defined (or maybe not!) in subclasses.
+
+[version 0.32_xx]
+
=item cbuilder()
[version 0.2809]