Skip to content

yusukebe/Hitagi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hitagi

Shall we talk about stars and micro web application frameworks.

SYNOPSIS

Write as

use Hitagi;
get '/' => sub { 'Hello' };
star;

Run it

$ perl myapp.pl

View at http://localhost:5000

DESCRIPTION

Hitagi is yet another micro web application framework using Plack::Request, Router::Simple, Text::MicroTemplate, and DBIx::Skinny.

EXAMPLE

Using template in DATA section.

Template format is as Text::MicroTemplate.

use Hitagi;
get '/' => 'index';
star;

__DATA__

@@ index
<h1>welcome</h1>

Get params and give args to template

use Hitag;
get '/hi' => sub {
    my ($req) = @_;
    render( 'hi.mt',
        { message => $req->param('message') || 'no message' } );
};
star;

__DATA__

@@ hi
<h1>message : <?= $message ?></h1>

Handle post request and parse params from url path

post '/comment/:id' => sub {
    my ( $req, $args ) = @_;
    warn "Comment id is : $args->{id}";
    ...;
};

Handle static files

Put your css or image files etc. to "static" directory. You can access these files on http://localhost:5000/static/xxx.css

Make custom response such as XML

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>

Template layout setting

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>

Model

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

Run as CGI, PSGI.

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

SEE ALSO

  • Plack::Request
  • Plack::Response
  • Text::MicroTemplate
  • DBIx::Skinny
  • Router::Simple
  • Data::Section::Simple

AUTHOR

Yusuke Wada ( aka yusukebe )


Currently, Hitagi is not CPAN module.

INSTALLATION

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

DOCUMENTATION

Hitagi documentation is available as in POD. So you can do:

% perldoc Hitagi

to read the documentation online with your favorite pager.

Yusuke Wada

About

Shall we talk about stars and micro web application frameworks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published