NAME
Footprintless::Plugin - The base class for footprintless plugins
VERSION
version 1.04
DESCRIPTION
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:
# $FPL_HOME/config/footprintless.pm
return {
plugins => [
'Foo::Plugin',
'Bar::Plugin'
]
};
Then you can use the methods directly on the footprintless instance:
my $footprintless = Footprintless->new();
my $foo = $footprintless->foo();
If you want to add commands, just add a module under the package returned by command_packages (defaults to 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
CONSTRUCTORS
new()
Creates a new plugin.
METHODS
command_packages()
Returns a list of packages to scan for commands.
factory_methods()
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.
AUTHOR
Lucas Theisen <lucastheisen@pastdev.com>
COPYRIGHT AND LICENSE
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.
SEE ALSO
Please see those modules/websites for more information related to this module.