Skip to content

Instantly share code, notes, and snippets.

@ichigotake
Last active December 15, 2015 18:39
Show Gist options
  • Select an option

  • Save ichigotake/5305657 to your computer and use it in GitHub Desktop.

Select an option

Save ichigotake/5305657 to your computer and use it in GitHub Desktop.
YanchaプラグインでWEBページを作成するサンプル
=encoding utf8
=head1 NAME
Yancha::Plugin::WebPageSample - WEBページを作成するYanchaプラグインの例
=head1 CONFIG
### add config.pl, and you can access with web browser!
#
# api_endpoint => {
# '/sample' => [ 'Yancha::Plugin::WebPageSample' => {} => 'Web page sample!' ],
# ...
=head1 AUTHOR
ichigotake
=head1 SEE ALSO
https://github.com/uzulla/yancha
=cut
package Yancha::Plugin::WebPageSample;
use strict;
use warnings;
use Data::Section::Simple;
use Mojo::Template;
use parent qw/Yancha::API/;
# web page
sub run {
my ( $self ) = @_;
my $res = $self->response();
my $mt = Mojo::Template->new;
my $output = $mt->render( get_data_section('index.html.ep'), 'It Works!');
$res->body( $output );
$res->content_type('text/html');
return $res;
}
1;
__DATA__
@@ index.html.ep
% my ($message) = @_;
<h1>Yancha::Plugin::WebPageSample</h1>
<%= $message %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment