NAME
Cot::Plugin - Cot plugin base module
SYNOPSIS
For example, Text::Xslate plugin is below(It's only a example!).
use strict;
use warnings;
use parent Cot::Plugin;
use Text::Xslate;
### "init" is initialize method only called once.
sub init {
my ( $self, $c ) = @_;
# in "init" adding "tx" method to Cot context object.
$c->tx($self);
}
### define plugin methods
# "tx" method can call "output";
sub output {
my $self = shift;
my $txfile = shift;
my $param = shift;
my $tx = Text::Xslate->new;
$tx->render( $txfile, $param );
}
1;
__END__
You can use in a Cot application.
use Cot;
use Cot::Plugin qw/TX/;
# or use Cot::Plugin::TX;
get '/' => sub {
my $self = shift;
$self->res->status(200);
$self->res->headers({'Content-Type' => 'text/plain' });
# you can call "tx" plugin
my $out = $self->tx->output('/path/to/template', { hello => 'world' });
$self->res->body($out);
};
DESCRIPTION
Cot::Plugin is base class of Plugins.
LICENSE
Copyright (C) Yusuke Shibata
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Yusuke Shibata <shibata@yusukeshibata.jp>