MozRepl::Plugin::Base - Plugin base class.


MozRepl documentation Contained in the MozRepl distribution.

Index


Code Index:

NAME

Top

MozRepl::Plugin::Base - Plugin base class.

VERSION

Top

version 0.03

SYNOPSIS

Top

    package MozRepl::Plugin::Foo::Bar;

    use strict;
    use warnings;

    use base qw(MozRepl::Plugin::Base);

    sub execute {
        my ($self, $ctx, $args) = @_;

        $ctx->execute(q|window.alert("Anta ga taisho!")|);
    }

    1;

    package main;

    use MozRepl;

    my $repl = MozRepl->new;
    $repl->setup({ plugins => { plugins => [qw/Foo::Bar/] } });
    $repl->foo_bar();

DESCRIPTION

Top

This module is base class any plugins for MozRepl.

METHODS

Top

new($args)

Create instance.

$args

Hash reference.

setup($ctx, @args)

Called from MozRepl setup() method. This is abstract method, If you want to task in setup pharse, then must be overriding this method.

$ctx

Context object. See MozRepl

@args

Extra parameters.

execute($ctx, @args)

Execute plugin method. Please override me.

$ctx

Context object. See MozRepl

@args

Extra parameters.

method_name()

If you override this method and return constant string, then the string will be used as method name in context.

Not overriding method name will be determined by MozRepl::Util plugin_to_method() method. See plugin_to_method($plugin, $search) in MozRepl::Util

process($name, $vars)

Processing template using by Template, Template::Provider::FromDATA.

$name

Label name in DATA Section.

$vars

Append values as hash reference.

SEE ALSO

Top

MozRepl
Template
Template::Provider::FromDATA

AUTHOR

Top

Toru Yamaguchi, <zigorou@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-mozrepl-plugin-base@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


MozRepl documentation Contained in the MozRepl distribution.
package MozRepl::Plugin::Base;

use strict;
use warnings;

use base qw(Class::Accessor::Fast);

use Carp::Clan qw(croak);
use Template;
use Template::Provider::FromDATA;

__PACKAGE__->mk_accessors($_) for (qw/template/);

our $VERSION = '0.03';

sub new {
    my ($class, $args) = @_;

    my $provider = Template::Provider::FromDATA->new({
        CLASSES => $class
    });
    $args->{template} = Template->new({
        LOAD_TEMPLATES => [$provider],
        PRE_CHOMP => 1
    });

    my $self = $class->SUPER::new($args);

    return $self;
}

sub setup {
    my ($self, $ctx, @args) = @_;
}

sub execute {
    my ($self, $ctx, @args) = @_;

    croak('Please override this method');
}

sub method_name {
    return "";
}

sub process {
    my ($self, $name, $vars) = @_;

    my $output = '';

    $self->template->process($name, $vars, \$output);
    return $output;
}

1; # End of MozRepl::Plugin::Base