NAME
Vim::Helper::Plugin - Base class and API for writing new plugins
DESCRIPTION
This package acts as a base class for all plugins. It also provides an API for writing new plugins quickly and efficiently. When you use Vim::Helper::Plugin
it automatically sets itself as a base class on your class.
SYNOPSIS
package
Vim::Helper::MyPlugin;
use
strict;
use
warnings;
# Load the plugin base class, and specify our configuration options.
# A read/write accessor will be generated for every config option added.
# If a default is specified it will be used when no option is provided.
# Defaults can be wrapped in a sub if they need ot be generated per
# instance.
# If required is specified, the program will crash if the config does not
# specify the option.
use
Vim::Helper::Plugin(
config_option_foo
=> {
default
=>
'foo'
},
config_option_bar
=> {
default
=>
sub
{[
'bar'
]} },
config_option_baz
=> {
required
=> 1 },
);
#########################
# Override some methods:
# args and opts, each key must be a valid key for the type in Declare::CLI.
# An additional key of 'help' is accepted for use in the 'help' command.
# Both of these are optional, no need to override them
sub
args {{
key
=>
%CONFIG
}}
sub
opts {{
key
=>
%CONFIG
}}
# VIMRC content (if we have any, otherwise do not override)
sub
vimrc {
my
$self
=
shift
;
my
(
$helper
,
$opts
) =
@_
;
my
$cmd
=
$helper
->command(
$opts
);
...
return
$VIMRC_CONTENT
;
}
#########################
# Add our own methods:
sub
do_something {
my
$self
=
shift
;
...
}
1;
METHODS
- $args = $CLASS->args()
-
Get the hashref of args provided by this plugin.
- $opts = $CLASS->opts()
-
Get the hashref of opts provided by this plugin.
- $obj = $CLASS->new()
-
Create a new instance.
- $vimrc = $obj->vimrc( $helper, $opts )
-
Generate the vimrc content for this plugin.
- $obj->config( { key => 'value', ... } )
-
You probably should not override this unless you REALLY want to change how your classes configuration function behaves.
For each key it will set the proper accessor. If a required key is omitted an error is thrown. If a key is invalid an error will be thrown.
AUTHORS
Chad Granum exodist7@gmail.com
COPYRIGHT
Copyright (C) 2012 Chad Granum
Vim-Helper is free software; Standard perl licence.
Vim-Helper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.