Skip Menu |
 

This queue is for tickets about the Module-Build CPAN distribution.

Report information
The Basics
Id: 18017
Status: resolved
Priority: 0/
Queue: Module-Build

People
Owner: Nobody in particular
Requestors: dmartin [...] sccd.ctc.edu
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Subclassing Example for Module::Build::Cookbook
Download (untitled) / with headers
text/plain 798b
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
Download Cookbook.diff
text/x-diff 1.4k
--- 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
Download (untitled) / with headers
text/plain 2.2k
Thanks for the patch. I've applied it in a somewhat edited form, shown below. -Ken Index: Changes ========================================================= ========== RCS file: /cvsroot/module-build/Module-Build/Changes,v retrieving revision 1.434 diff -u -r1.434 Changes --- Changes 4 Mar 2006 03:59:28 -0000 1.434 +++ Changes 7 Mar 2006 03:57:04 -0000 @@ -5,6 +5,9 @@ - Added a 'testpodcoverage' action that runs a POD coverage check for all modules in the distribution. [Yanick Champoux] + - Added a Cookbook example of subclassing to modify an action. [Dylan + Martin and David Golden] + 0.27_08 Fri Mar 3 21:22:41 CST 2006 - Due to shell quoting issues and differences in syntax between Index: lib/Module/Build/Cookbook.pm ========================================================= ========== RCS file: /cvsroot/module-build/Module-Build/lib/Module/Build/Cookbook.pm,v retrieving revision 1.21 diff -u -r1.21 Cookbook.pm --- lib/Module/Build/Cookbook.pm 4 Mar 2006 00:42:45 -0000 1.21 +++ lib/Module/Build/Cookbook.pm 7 Mar 2006 03:57:04 -0000 @@ -329,6 +329,40 @@ =back 4 +=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 or do something else peculiar to your application. + +You can subclass C<Module::Build> on the fly using the C<subclass()> +method and override the methods that perform the actions. You may need +to read through C<Module::Build::Authoring> to find the methods you +want to override, but the general pattern is C<ACTION_> followed by +the name of the action you want to modify. Here's an example of how +it would work for C<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 0.27 or above for more +complete documentation on this. + =head1 AUTHOR Ken Williams <ken@cpan.org>


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.