PAD::Plugin - base class for writing pad plugin
package PAD::Plugin::Static; use parent 'PAD::Plugin'; use Plack::App::File; sub execute { my $self = shift; Plack::App::Directory->new->to_app->($self->request->env); }
suffix
Specifies the suffix of file (in regexp) that to be filtered.
# e.g.) for markdown file, sub suffix { qr/\.md$/ }
content_type
Defines Content-Type of response. Default is text/plain; charset=UTF-8.
text/plain; charset=UTF-8
# e.g.) serve HTML file, sub content_type { 'text/html; charset=UTF-8' }
request
Accessor of the Plack::Request. You can call this method in execute method.
Plack::Request
execute
relative_path
Converts PATH_INFO into relative path. This method is convenient for opening file.
PATH_INFO
open
Write the main logic here.
# e.g.) renders a markdown document and returns C<finalized> PSGI response sub execute { my $self = shift; my $path = $self->relative_path; open my $text, '<', $path or die $!; my $md = markdown(do { local $/; <$text> }); my $res = $self->request->new_response(200, ['Content-Type' => $self->content_type], $md); $res->finalize; }
punytan <punytan@gmail.com>
PAD, PAD::Plugin::Static, PAD::Plugin::Markdown
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install PAD, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PAD
CPAN shell
perl -MCPAN -e shell install PAD
For more information on module installation, please visit the detailed CPAN module installation guide.