diff --git a/Changes b/Changes index b425c82..b77466e 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for Plugin-Simple - fix missing closing single quote in SYNOPSIS (closes #10) - remove CONTRIBUTING section in POD (closes #9) - fix incorrect sub name in POD and warnings (closes #7) + - added example use case in EXAMPLE (closes #8) 0.07 2016-03-28 - fixed a missed croak() if a plugin file can't be found, breaking diff --git a/lib/Plugin/Simple.pm b/lib/Plugin/Simple.pm index 5394bfc..6e59cf3 100644 --- a/lib/Plugin/Simple.pm +++ b/lib/Plugin/Simple.pm @@ -244,6 +244,51 @@ To use both options, simply separate them with a comma. None. We simply install a C function within the namespace of the package that Cd us. +=head1 EXAMPLE + +This example simply uses a single plugin module with a C +function. In the script, we load this file, and check to ensure the plugin does +in fact have that sub available. + +We then call the plugins in a loop (even though in this case there's only one), +and send in an argument for the plugin to do work on. + +=head2 Script + + use warnings; + use strict; + + use lib '.'; + + use Plugin::Simple; + + my @plugins = plugins( + 'examples/TestPlugin.pm', + can => ['plugin_function'] + ); + + my $plugin_arg = 'Hello!'; + + for my $plugin (@plugins){ + $plugin->plugin_function($plugin_arg); + } + +=head2 Plugin Module + + package TestPlugin; + + sub plugin_function { + shift; # throw away class/obj + my ($str) = @_; + print "in " . __PACKAGE__ . ", arg is: $str\n"; + } + + 1; + +=head2 Output + + in TestPlugin, arg is: Hello! + =head1 AUTHOR Steve Bertrand, C<< >>