Footprintless::Plugin - The base class for footprintless plugins
version 1.24
This class serves as a base class for plugins. It defines the mandatory interface that a plugin must implement. Plugins add methods to the factory itself at runtime. For example:
package Foo::Plugin; use parent qw(Footprintless::Plugin); sub foo { require Foo; return Foo->new(); } sub factory_methods { my ($self) = @_; return { foo => sub { return $self->foo(@_); } } } package Foo; sub new() { return bless({}, shift); } sub bar { print("BAR"); }
Then they can be registered with a factory instance:
$factory->register_plugin(Foo::Plugin->new());
Or, they can be registered via configuration in the footprintless.plugins entity:
footprintless.plugins
# $FPL_HOME/config/footprintless.pm return { plugins => [ 'Foo::Plugin', 'Bar::Plugin' ], 'Foo::Plugin' => { # optional config } 'Bar::Plugin' => { # optional config } };
Then you can use the methods directly on the footprintless instance:
my $footprintless = Footprintless->new(); my $foo = $footprintless->foo();
If a key with the same name as the plugin is present in the footprintless entity, then the entire hashref will be set as $self-{config}> on the plugin instance during construction. You can then override the _init() method to do configuration based initialization.
footprintless
$self-
_init()
If you want to add commands, just add a module under the package returned by command_packages (defaults to ref($self) . '::Command'):
ref($self) . '::Command'
package Foo::Plugin::Command::foo use Footprintless::App -command; sub execute { my ($self, $opts, $args) = @_; my $foo = $self->app()->footprintless()->foo(); $foo->bar(); }
Then your command will be availble from the fpl command:
$> fpl foo BAR
Creates a new plugin.
Returns a list of packages to scan for commands.
Returns a hash full of factory methods. The key will be used as the method name that gets registered with the factory. Its value must be a reference to a sub.
Lucas Theisen <lucastheisen@pastdev.com>
This software is copyright (c) 2016 by Lucas Theisen.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please see those modules/websites for more information related to this module.
Footprintless
To install Footprintless, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Footprintless
CPAN shell
perl -MCPAN -e shell install Footprintless
For more information on module installation, please visit the detailed CPAN module installation guide.