Skip to content

Commit

Permalink
removed custom Mojolicious::Lite keyword recipe and tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 20, 2012
1 parent 5029e41 commit f5e97f5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
34 changes: 0 additions & 34 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1082,40 +1082,6 @@ namespace.

1;

=head2 Adding keywords to Mojolicious::Lite

Since L<Mojolicious::Lite> keywords have to be added at compile time, they
require their own exporter module instead of a plugin.

package Mojolicious::Lite::GetPost;
use Mojo::Base -base;

use Mojo::Util 'monkey_patch';

sub import {

# Save caller package so function can be called from everywhere
my $caller = caller;
monkey_patch $caller, 'get_post', sub {
return $caller->app->routes->any([qw(GET POST)] => @_);
};
}

Just access the application through the caller's package and you have its full
functionality at your disposal.

use Mojolicious::Lite;
use Mojolicious::Lite::GetPost;

# Accept only GET and POST requests
get_post '/whatever' => sub {
my $self = shift;
my $method = $self->req->method;
$self->render(text => "You called /whatever with $method.");
};

app->start;

=head2 Running code against your application

Ever thought about running a quick oneliner against your L<Mojolicious>
Expand Down
5 changes: 2 additions & 3 deletions t/mojolicious/layouted_lite_app.t
Expand Up @@ -12,7 +12,6 @@ use FindBin;
use lib "$FindBin::Bin/lib";

use Mojolicious::Lite;
use LiteTestKeyword;
use Test::Mojo;

# Plugin with a template
Expand All @@ -23,8 +22,8 @@ app->renderer->paths->[0] = app->home->rel_dir('does_not_exist');
# Default layout for whole application
app->defaults(layout => 'default');

# GET /works (custom keyword)
test_keyword '/works';
# GET /works
get '/works';

# GET /doenotexist
get '/doesnotexist';
Expand Down
11 changes: 0 additions & 11 deletions t/mojolicious/lib/LiteTestKeyword.pm

This file was deleted.

0 comments on commit f5e97f5

Please sign in to comment.