Yeb - A simple structure for Web::Simple applications
version 0.101
package MyApp::Web; use Yeb; BEGIN { plugin 'Session'; plugin 'JSON'; } r "/" => sub { session test => pa('test'); text "root"; }; r "/blub" => sub { text "blub"; }; r "/test/..." => sub { st stash_var => 1; chain 'Test'; }; r "/blog/..." => sub { chain '+SomeOther::YebApp'; }; 1; package MyApp::Web::Test; use MyApp::Web; r "/json" => sub { json { test => session('test'), stash_var => st('stash_var'), } }; r "/" => sub { text " test = ".session('test')." and blub is ".st('stash_var'); }; 1;
Can then be started like (see Web::Simple):
plackup -Ilib -MMyApp::Web -e'MyApp::Web->run_if_script'
or use the yeb CLI tool which automatically also loads up ./lib as path for easy handling:
yeb MyApp::Web
Additional parameters get dispatched towards plackup
Bigger Text::Xslate example:
package MyApp::WebXslate; use Yeb; BEGIN { plugin 'Session'; plugin 'JSON'; plugin 'Xslate'; plugin 'Static', default_root => root('htdocs'); } xslate_path root('templates'); static qr{^/}; static_404 qr{^/images/}, root('htdocs_images'); r "/" => sub { st page => 'root'; xslate 'index'; }; r "/test" => sub { st page => 'test'; xslate 'index/test', { extra_var => 'extra' }; }; 1;
ALPHA This web framework is made to be used for YACT, a new version of the Act conference system. With the release of YACT the API will be stabilized. ALPHA
For an example on how to make a simple plugin, which adds a new function and uses a Plack::Middleware, please see the source of Yeb::Plugin::Session.
Gives back the Yeb::Application of the web application
Return another class dispatcher chain, will be prepend with your main class name, this can be deactivated by using a + in front of the class name.
Access to the configuration hash
Getting the current Yeb::Context of the request
Getting the Plack environment
Getting the current Plack::Request
Current directory or YEB_ROOT environment variable
Current directory in the moment of start
Access to the stash hash
Access to the request parameters, gives back "" if is not set
Check if some parameter is at all set
Adding a new dispatcher for this class (see Web::Simple)
Adding a Plack::Middleware to the flow
Make a simple text/plain response with the text given as parameter
Session management via Plack::Middleware::Session
Static files via Plack::Middleware::Static
Template output via Text::Xslate
JSON output via JSON
IRC
Join #web-simple on irc.perl.org. Highlight Getty for fast reaction :).
Repository
http://github.com/Getty/p5-yeb Pull request and additional contributors are welcome
Issue Tracker
http://github.com/Getty/p5-yeb/issues
Torsten Raudssus <torsten@raudss.us>
This software is copyright (c) 2013 by Torsten Raudssus.
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 Yeb, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Yeb
CPAN shell
perl -MCPAN -e shell install Yeb
For more information on module installation, please visit the detailed CPAN module installation guide.