NAME

PAD::Plugin - base class for writing pad plugin

SYNOPSIS

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);
}

METHODS

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.

# 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.

relative_path

Converts PATH_INFO into relative path. This method is convenient for opening file.

execute

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;
}

AUTHOR

punytan <punytan@gmail.com>

SEE ALSO

PAD, PAD::Plugin::Static, PAD::Plugin::Markdown

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.