NAME

Padre::Plugin::Shell::Base - A base class for Padre plugins.

DESCRIPTION

Base class for plugins that use the system shell to extend Padre.

Example

Subclass Padre::Plugin::Shell::Base to create a plugin.

package Padre::Plugin::Shell::Foo;
use base 'Padre::Plugin::Shell::Base';

use 5.008;
use strict;
use warnings;
use Padre::Wx       ();

sub plugin_menu {
    my ($self) = @_;
    my @menu   = ();
    push @menu, "Do Foo" => sub {$self->do_foo()};
    push @menu, '---' => undef;
    push @menu, Wx::gettext("&Configure Foo") => sub { $self->edit_config_file() },;
    return @menu;
}

sub example_config {
    my ($self) = @_;
    my $config = "---\n";

    # additional config
    return $config;
}

sub do_foo {
    my ( $self ) = @_;
    my %config = $self->get_config();

    # additional foo
}
1;

Subclass Padre::Plugin to wrap the plugin.

package Padre::Plugin::Foo;
use base 'Padre::Plugin';

use 5.008;
use strict;
use warnings;
use Padre::Plugin ();
use Padre::Plugin::Shell::Foo;

our $VERSION = '0.01';

my $foo_plugin;

sub plugin_name {
    'Foo';
}

sub padre_interfaces {
    'Padre::Plugin' => 0.43;
}

sub menu_plugins_simple {
    my ($self) = @_;
    $foo_plugin = Padre::Plugin::Shell::Foo->new();
    'Foo' => [$plugin->plugin_menu()];
}
1;

ENVIRONMENT VARIABLES

To provide additional information for the plugins, the following environment variables are set prior to performing the plugin action:

    PE_CURRENT_WORD -- The word at the caret position.
    PE_CURRENT_LINE -- The text of the current line.
    PE_COLUMN_INDEX -- The index of the position of the caret in the current line (counting from 0).
    PE_COLUMN_NUMBER -- The column number of the caret in the current line (counting from 1).
    PE_LINE_INDEX -- The index of the current line (counting from 0).
    PE_LINE_NUMBER -- The line number of the current line (counting from 1).
    PE_LINE_COUNT -- The count of lines in the document.
    PE_BASENAME -- The file name of the current document.
    PE_DIRECTORY -- The directory of the current document.
    PE_FILEPATH -- The full path and name of the current document.
    PE_MIMETYPE -- The mime-type of the current document.
    PE_CONFIG_DIR -- Location of the configuration directory (~/.padre)
    PE_DEF_PROJ_DIR -- The default project directory.
    PE_INDENT_TAB -- Use tabs for indentation. 'YES' or 'NO'
    PE_INDENT_TAB_WIDTH -- Tab width/size.
    PE_INDENT_WIDTH -- Indentation width/size.

METHODS

Document/file interaction methods

append_selection_from_file ($file_pathname)

Takes the contents of $file_pathname and appends it to after the selection in the current editor tab.

new_document_from_file ($file_pathname, $mimetype)

Creates a new document from the contents in $file_pathname. The (optional) $mimetype tells Padre what kind of document is being created. If no mimetype is specified the Padre will be attempt to guess the mimetype.

replace_selection_from_file ($file_pathname)

Takes the contents of $file_pathname and uses it to replace the selection in the current editor tab.

File utility methods

get_temp_file

Creates a temporary file and returns the pathname of the temporary file.

delete_temp_file ($file_pathname)

Deletes a temporary file.

slurp_file ($file_pathname)

Returns the contents of the specified file.

Configuration file methods

NOTE: Plugin configurations are stored using YAML.

config_file

Returns the pathname of a plugin configuration file.

edit_config_file

Opens the configuration file for a plugin for editing.

example_config

Returns an example configuration for a plugin. Is to be overwritten by plugins that subclass this package.

get_config

Returns a hash containing the configuration for a plugin.

initialize_config_file

Initializes a configuration file for a plugin using the return value from example_config.

Environment variable methods

update_environment_vars

Updates the environment variables supported by plugins that subclass this package. See the ENVIRONMENT VARIABLES section for details.

Other methods

new

The cannonical new method.

plugin_menu

Returns the menu for a plugin. Is to be overwritten by plugins that subclass this package.

notify_of_error

Displays an error message.

AUTHOR

Gregory Siems <gsiems@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Gregory Siems

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.