Kossy
view release on metacpan or search on metacpan
lib/Kossy.pm view on Meta::CPAN
if ( !$_FILTER->{$class} ) {
$_FILTER->{$class} = {};
}
if ( @_ ) {
$_FILTER->{$class}->{$_[0]} = $_[1];
}
$_FILTER->{$class};
}
sub _wrap_filter {
my $klass = shift;
my $class = ref $klass ? ref $klass : $klass;
if ( !$_FILTER->{$class} ) {
$_FILTER->{$class} = {};
}
my ($filter,$app) = @_;
my $filter_subref = $_FILTER->{$class}->{$filter};
Carp::croak sprintf("Filter:%s is not exists", $filter) unless $filter_subref;
return $filter_subref->($app);
}
1;
__END__
=head1 NAME
Kossy - Sinatra-ish Simple and Clear web application framework
=head1 SYNOPSIS
% kossy-setup MyApp
% cd MyApp
% plackup app.psgi
## lib/MyApp/Web.pm
use Kossy;
get '/' => sub {
my ( $self, $c ) = @_;
$c->render('index.tx', { greeting => "Hello!" });
};
get '/json' => sub {
my ( $self, $c ) = @_;
my $result = $c->req->validator([
'q' => {
default => 'Hello',
rule => [
[['CHOICE',qw/Hello Bye/],'Hello or Bye']
],
}
]);
$c->render_json({ greeting => $result->valid->get('q') });
};
1;
## views/index.tx
: cascade base
: around content -> {
<: $greeting :>
: }
=head1 DESCRIPTION
Kossy is Sinatra-ish Simple and Clear web application framework, which is based upon L<Plack>, L<Router::Boom>, L<Text::Xslate> and build-in Form-Validator. That's suitable for small application and rapid development.
=head1 Kossy class
Kossy exports some methods to building application
=head2 CLASS METHODS for Kossy class
=over 4
=item my $kossy = Kossy->new( root_dir => $root_dir );
Create instance of the application object.
=back
=head2 OBJECT METHODS for Kossy class
=over 4
=item my $root_dir = $kossy->root_dir();
accessor to root directory of the application
=item my $app = $kossy->psgi();
return PSGI application
=back
=head2 DISPATCHER METHODS for Kossy class
=over 4
=item filter
makes application wrapper like plack::middlewares.
filter 'set_title' => sub {
my $app:CODE = shift;
sub {
my ( $self:Kossy, $c:Kossy::Connection ) = @_;
$c->stash->{site_name} = __PACKAGE__;
$app->($self,$c);
}
};
=item get path:String => [[filters] =>] CODE
=item post path:String => [[filters] =>] CODE
setup router and dispatch code
get '/' => [qw/set_title/] => sub {
( run in 2.044 seconds using v1.01-cache-2.11-cpan-9581c071862 )