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/); =head1 NAME MozRepl::Plugin::Base - Plugin base class. =head1 VERSION version 0.03 =cut our $VERSION = '0.03'; =head1 SYNOPSIS 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(); =head1 DESCRIPTION This module is base class any plugins for MozRepl. =head1 METHODS =head2 new($args) Create instance. =over 4 =item $args Hash reference. =back =cut 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; } =head2 setup($ctx, @args) Called from L setup() method. This is abstract method, If you want to task in setup pharse, then must be overriding this method. =over 4 =item $ctx Context object. See L =item @args Extra parameters. =back =cut sub setup { my ($self, $ctx, @args) = @_; } =head2 execute($ctx, @args) Execute plugin method. Please override me. =over 4 =item $ctx Context object. See L =item @args Extra parameters. =back =cut sub execute { my ($self, $ctx, @args) = @_; croak('Please override this method'); } =head2 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 L plugin_to_method() method. See L =cut sub method_name { return ""; } =head2 process($name, $vars) Processing template using by L