Cot::Plugin - Cot plugin base module
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); };
Cot::Plugin is base class of Plugins.
Copyright (C) Yusuke Shibata
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Yusuke Shibata <shibata@yusukeshibata.jp>
To install Cot, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cot
CPAN shell
perl -MCPAN -e shell install Cot
For more information on module installation, please visit the detailed CPAN module installation guide.