Subject: | Subclassing Example for Module::Build::Cookbook |
I've attached a patch to Cookbook.pm that would insert the example as I
would add it.
Basically, I was trying to figure out how to customize the 'install'
action, and I couldn't really figure it out from the documentation. I
needed the 'install' action to change the ownership of a file. I asked
on Perl Monks, and xdg gave me this really simple answer that made the
light-bulb go off in my head. So, I thought it would be great if you
included his example in the Cookbook.
I told him I was going to recommend you include his example in the
documentation, but I don't have his permission or anything like that.
I'm pretty sure his posting it on Perl Monks means you can quote him.
Anyway, I ran up the attached patch file. So, there you go.
Thanks for the awesome module!
--Pileofrogs
Subject: | Cookbook.diff |
--- Cookbook.pm.orig 2006-03-06 11:03:55.000000000 -0800
+++ Cookbook.pm 2006-03-06 12:46:24.000000000 -0800
@@ -260,6 +260,40 @@
that first appeared in version 0.26. Before that it could certainly
still be done, but the simple cases took a bit more work.
+=head2 Modifying an action
+
+Sometimes you might need an to have an action, say C<./Build install>,
+do something
+unusual. For instance, you might need to change the ownership of a file.
+Here's an example posted on Perl Monks by xdg.
+
+You can subclass C<Module::Build> on the fly using the subclass method and
+override the methods that perform the actions. You may need to read through
+C<Module::Build::Base> to find the methods you want to override, but the general
+pattern is C<ACTION_> followed by the name of the action you'd put after
+"Build". Here's an example of how it would work for install:
+
+ # Build.PL
+ use Module::Build;
+ my $class = Module::Build->subclass(
+ class => "Module::Build::Custom",
+ code => <<'SUBCLASS', );
+
+ sub ACTION_install {
+ my $self = shift;
+ # YOUR CODE HERE
+ $self->SUPER::ACTION_install;
+ }
+ SUBCLASS
+
+ $class->new(
+ module_name => 'Your::Module',
+ # rest of the usual Module::Build parameters
+ )->create_build_script;
+
+See the C<Module::Build::Authoring> pod in any of the 0.27 developer releases
+for better documentation on this.
+
=head1 AUTHOR
Ken Williams, ken@mathforum.org