diff --git a/dist.ini b/dist.ini index 39e6b3a..d083c43 100644 --- a/dist.ini +++ b/dist.ini @@ -1,5 +1,5 @@ name = Devel-PatchPerl -version = 0.62 +version = 0.64 author = Chris Williams license = Perl_5 copyright_holder = Chris Williams and Marcus Holland-Moritz @@ -12,3 +12,4 @@ File::pushd = 1.00 IO::File = 0 IPC::Cmd = 0.40 MIME::Base64 = 0 +Module::Pluggable = 0 diff --git a/lib/Devel/PatchPerl.pm b/lib/Devel/PatchPerl.pm index 792c1fd..5c4e3a4 100644 --- a/lib/Devel/PatchPerl.pm +++ b/lib/Devel/PatchPerl.pm @@ -9,6 +9,7 @@ use File::Spec; use IO::File; use IPC::Cmd qw[can_run run]; use Devel::PatchPerl::Hints qw[hint_file]; +use Module::Pluggable search_path => ['Devel::PatchPerl::Plugin']; use vars qw[@ISA @EXPORT_OK]; @ISA = qw(Exporter); @@ -161,9 +162,41 @@ sub patch_source { $sub->(@args); } } + _process_plugin( version => $vers, source => $source, patchexe => $patch_exe ); } } +sub _process_plugin { + my %args = @_; + return unless my $possible = $ENV{PERL5_PATCHPERL_PLUGIN}; + my ($plugin) = grep { $possible eq $_ or /\Q$possible\E$/ } __PACKAGE__->plugins; + unless ( $plugin ) { + warn "# You specified a plugin '", $ENV{PERL5_PATCHPERL_PLUGIN}, + "' that isn't installed, just thought you might be interested.\n"; + return; + } + { + local $@; + eval "require $plugin"; + if ($@) { + die "# I tried to load '", $ENV{PERL5_PATCHPERL_PLUGIN}, + "' but it didn't work out. Here is what happened '$@'\n"; + } + } + { + local $@; + eval { + $plugin->patchperl( + %args, + ); + }; + if ($@) { + warn "# Warnings from the plugin: '$@'\n"; + } + } + return 1; +} + sub _is { my($s1, $s2) = @_; @@ -1778,9 +1811,15 @@ current working directory. =back +=head1 PLUGIN SYSTEM + +See L for details of Devel::PatchPerl's plugin system. + =head1 SEE ALSO L +L + =cut diff --git a/lib/Devel/PatchPerl/Plugin.pm b/lib/Devel/PatchPerl/Plugin.pm new file mode 100644 index 0000000..e72752a --- /dev/null +++ b/lib/Devel/PatchPerl/Plugin.pm @@ -0,0 +1,67 @@ +package Devel::PatchPerl::Plugin; + +#ABSTRACT: Devel::PatchPerl plugins explained + +use strict; +use warnings; + +qq[Plug it in]; + +=pod + +=head1 DESCRIPTION + +This document explains the L plugin system. + +Plugins are a mechanism for providing additional functionality to +L. + +Plugins are searched for in the L namespace. + +=head1 INITIALISATION + +The plugin constructor is C. + +A plugin is specified using the C environment +variable. It may either be specified in full (ie. C) +or as the short part (ie. C). + + $ export PERL5_PATCHPERL_PLUGIN=Devel::PatchPerl::Plugin::Feegle + + $ export PERL5_PATCHPERL_PLUGIN=Feegle + +When L has identified the perl source patch and done its patching +it will attempt to load the plugin identified. It will then call the class method +C for the plugin package, with the following parameters: + + 'version', the Perl version of the source tree; + 'source', the absolute path to the Perl source tree; + 'patchexe', the 'patch' utility that can be used; + +Plugins are called with the current working directory being the root of the +Perl source tree, ie. C. + +Summarised: + + $ENV{PERL5_PATCHPERL_PLUGIN} = 'Devel::PatchPerl::Plugin::Feegle'; + + my $plugin = $ENV{PERL5_PATCHPERL_PLUGIN}; + + eval "require $plugin"; + + eval { + $plugin->patchperl( version => $vers, source => $srcdir, patchexe => $patch ); + }; + +=head1 WHAT CAN PLUGINS DO? + +Anything you desire to a Perl source tree. + +=head1 WHY USE AN ENVIRONMENT VARIABLE TO SPECIFY PLUGINS? + +So that indicating a plugin to use can be specified independently of whatever mechanism is +calling L to do its bidding. + +Think L. + +=cut diff --git a/t/03_plugin.t b/t/03_plugin.t new file mode 100644 index 0000000..13a5dad --- /dev/null +++ b/t/03_plugin.t @@ -0,0 +1,11 @@ +use strict; +use warnings; +use lib 't/lib'; +BEGIN { + $ENV{PERL5_PATCHPERL_PLUGIN} = 'TEST'; +} +use Test::More qq'no_plan'; +use File::Spec; +use Devel::PatchPerl; +my $result = Devel::PatchPerl::_process_plugin(version => '5.14.2'); +ok( $result, 'The result was okay' ); diff --git a/t/lib/Devel/PatchPerl/Plugin/TEST.pm b/t/lib/Devel/PatchPerl/Plugin/TEST.pm new file mode 100644 index 0000000..9583a04 --- /dev/null +++ b/t/lib/Devel/PatchPerl/Plugin/TEST.pm @@ -0,0 +1,10 @@ +package Devel::PatchPerl::Plugin::TEST; + +use strict; +use warnings; + +sub patchperl { + warn "I AM A TEST PLUGIN\n"; +} + +qq[1];