Spike-2.0 - simple Plack::Request-based web framework
1. Install Spike package
2. spike add MySite
spike add MySite
3. cd MySite
cd MySite
4. rm -r web/mysite
rm -r web/mysite
5. ln -s /path/to/web/static/files web/mysite
ln -s /path/to/web/static/files web/mysite
6. plackup script/mysite.psgi
plackup script/mysite.psgi
use FindBin; use lib "$FindBin::Bin/../lib"; use DeadBeef::Site; DeadBeef::Site->run;
package DeadBeef::Site; use base qw(Spike); use HTTP::Status qw(:constants); sub startup { my $self = shift; $self->route ->prepare(sub { my ($req, $res) = @_; # place code here }) ->finalize(sub { my ($req, $res) = @_; # place code here }) ->error(HTTP_NOT_FOUND() => sub { my ($req, $res) = @_; # place code here }) ->error(HTTP_INTERNAL_SERVER_ERROR() => sub { my ($req, $res) = @_; # place code here }) ->get('/' => sub { my ($req, $res) = @_; # place code here }) ->post('/' => sub { my ($req, $res) = @_; # place code here }); } 1;
$new_route = $route->route('level1') $new_route = $route->route('level1/level2/...') $new_route = $route->route('*') $new_route = $route->route('#name') $new_route = $route->route('#name' => [qw(value1 value2 ...)]) $new_route = $route->route('#name' => qr/regexp/ }) $new_route = $route->route('#name' => sub { ... }) # all of the above together $new_route = $route->route('l1/#n1/l3' => sub { ... }) ->route('*/#n2/l6' => sub { ... }) $route = $route->get(sub { ... }) $route = $route->get('path' => sub { ... }) $route = $route->post(sub { ... }) $route = $route->post('path' => sub { ... }) $route = $route->all(sub { ... }) $route = $route->all('path' => sub { ... }) $route = $route->error(sub { ... }) $route = $route->error(404 => sub { ... }) $route = $route->error(Spike::Error::Class => sub { ... }) $route = $route->prepare(sub { ... }) $route = $route->finalize(sub { ... })
Plack, Plack::Request, Plack::Response
Aleksandr Aleshin <silencer2k@gmail.com>
Copyright (c) 2016 Aleksandr Aleshin
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Spike, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Spike
CPAN shell
perl -MCPAN -e shell install Spike
For more information on module installation, please visit the detailed CPAN module installation guide.