Shall we talk about stars and micro web application frameworks.
Write as
use Hitagi;
get '/' => sub { 'Hello' };
star;
Run it
$ perl myapp.pl
View at http://localhost:5000
Hitagi is yet another micro web application framework using Plack::Request, Router::Simple, Text::MicroTemplate, and DBIx::Skinny.
Template format is as Text::MicroTemplate.
use Hitagi;
get '/' => 'index';
star;
__DATA__
@@ index
<h1>welcome</h1>
use Hitag;
get '/hi' => sub {
my ($req) = @_;
render( 'hi.mt',
{ message => $req->param('message') || 'no message' } );
};
star;
__DATA__
@@ hi
<h1>message : <?= $message ?></h1>
post '/comment/:id' => sub {
my ( $req, $args ) = @_;
warn "Comment id is : $args->{id}";
...;
};
Put your css or image files etc. to "static" directory. You can access these files on http://localhost:5000/static/xxx.css
res method returns Plack::Response.
get '/xml' => sub {
my $res = res(200);
$res->content_type('application/xml');
$res->body( template('xml') );
$res->finalize;
};
...;
__DATA__
@xml
<xml><root>content</root></xml>
use Hitagi;
...;
__DATA__
@@ index
<h1>welcome</h1>
@@ layout
<html>
</head><title>title</title></head>
<body>
<div id="container">
<?= content ?>
</div>
<address>This content is made by Hitagi</address>
</body>
</html>
DBIx::Skinny based.
use Hitagi;
set db => {
connect_info => [ 'dbi:SQLite:','', '' ],
schema => qq{
install_table entry => schema {
pk 'id';
columns qw/id body/;
};
}
};
db->do(q{CREATE TABLE entry ( id varchar, body text )});
...;
get '/entry/{entry_id}' => sub {
my ( $req, $args ) = @_;
my $entry_id = $args->{entry_id};
my $entry = db->single( entry => { id => $entry_id, } );
return res(404,[],'Not Found')->finalize unless $entry;
render( 'entry', { body => $entry->body } );
};
If you save a application file with '.cgi' extention, it works as CGI.
/home/user/public_html/hello.cgi
#!/usr/bin/perl
use Hitagi;
get '/' => sub { render( 'index', { message => 'Hi' } ) };
star;
__DATA__
@@ index
<h1>message : <?= $message ?></h1>
View http://localhost/~user/hello.cgi/
PSGI supported too.
$ plackup myapp.pl
Yusuke Wada ( aka yusukebe )
Currently, Hitagi is not CPAN module.
Hitagi installation is straightforward. If your CPAN shell is set up, you should just be able to do
% cpan Hitagi
Download it, unpack it, then build it as per the usual:
% perl Makefile.PL
% make && make test
Then install it:
% make install
Hitagi documentation is available as in POD. So you can do:
% perldoc Hitagi
to read the documentation online with your favorite pager.
Yusuke Wada