Skip to content

Commit

Permalink
Merge branch 'topic/load_app'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Dec 27, 2011
2 parents 2fb3b34 + 10a4c76 commit 2a02d1f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/Dancer/Core/DSL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ sub hook {
$self->app->add_hook(Dancer::Core::Hook->new(name => $name, code => $code));
}

sub load_app {
my ($self, $app_name, %options) = @_;

# set the application
eval "use $app_name";
croak "Unable to load application \"$app_name\" : $@" if $@;

croak "$app_name is not a Dancer application"
if ! $app_name->can('dancer_app');
my $app = $app_name->dancer_app;

# FIXME not working yet
}


sub prefix {
my $app = shift->app;
@_ == 1
Expand Down
4 changes: 2 additions & 2 deletions t/lib/TestApp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ set 'default_mime_type' => 'text/bar';
get '/' => sub { app->name };

# /haltme should bounce to /
before sub {
hook 'before' => sub {
if (request->path_info eq '/haltme') {
redirect '/';
halt;
}
};
get '/haltme' => sub { "should not be there" };

after sub {
hook 'after' => sub {
my $response = shift;
if (request->path_info eq '/rewrite_me') {
$response->content("rewritten!");
Expand Down
20 changes: 20 additions & 0 deletions t/load_app.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use strict;
use warnings;
use Test::More import => ['!pass'];

BEGIN {
use Dancer;
load_app 't::lib::TestApp', prefix => '/test';
}

is( t::lib::TestApp->dancer_app->name, 't::lib::TestApp' );

use Dancer::Test 't::lib::TestApp';

response_status_is([GET => '/'], 404,
'route / is not found (prefix set)';

response_content_is([GET => '/test'], 't::lib::TestApp',
'route /test works');

done_testing;

0 comments on commit 2a02d1f

Please sign in to comment.