-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
244 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package CustomContext::Context; | ||
|
||
use Kelp::Base 'Kelp::Context'; | ||
use Kelp::Util; | ||
|
||
attr persistent_controllers => !!1; | ||
|
||
sub build_controller | ||
{ | ||
my ($self, $controller_class) = @_; | ||
|
||
$controller_class->new( | ||
app => $self->app, | ||
); | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package CustomContext::Controller; | ||
|
||
use Kelp::Base; | ||
use Carp; | ||
|
||
attr -app => sub { croak 'app is required' }; | ||
|
||
sub before_dispatch | ||
{ | ||
my $self = shift; | ||
$self->app->before_dispatch(@_); | ||
} | ||
|
||
sub before_finalize | ||
{ | ||
my $self = shift; | ||
$self->app->before_finalize(@_); | ||
} | ||
|
||
sub build | ||
{ | ||
my $self = shift; | ||
my $app = $self->app; | ||
|
||
$app->add_route( | ||
'/a' => { | ||
to => 'bridge', | ||
bridge => 1, | ||
} | ||
); | ||
$app->add_route('/a/b/c' => 'foo#test'); | ||
} | ||
|
||
sub bridge | ||
{ | ||
return ref shift() eq __PACKAGE__; | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package CustomContext::Controller::Foo; | ||
|
||
use Kelp::Base 'CustomContext::Controller'; | ||
|
||
sub test | ||
{ | ||
my ($self) = @_; | ||
|
||
$self->app->res->text; | ||
return ref $self; | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package MyApp3; | ||
use Kelp::Base 'Kelp'; | ||
|
||
attr context_obj => 'CustomContext::Context'; | ||
|
||
sub build | ||
{ | ||
my $self = shift; | ||
|
||
$self->routes->base('CustomContext::Controller'); | ||
$self->routes->rebless(1); | ||
|
||
$self->add_route( | ||
'/a/b' => { | ||
to => sub { | ||
return ref shift() eq __PACKAGE__; | ||
}, | ||
bridge => 1, | ||
} | ||
); | ||
$self->context->controller()->build; | ||
} | ||
|
||
1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use lib 't/lib'; | ||
use Kelp::Base -strict; | ||
use MyApp3; | ||
use Kelp::Test; | ||
use HTTP::Request::Common; | ||
use Test::More; | ||
|
||
# Get the app | ||
my $app = MyApp3->new(); | ||
|
||
# Test object | ||
my $t = Kelp::Test->new(app => $app); | ||
|
||
$t->request_ok(GET '/a/b/c') | ||
->content_type_is('text/plain') | ||
->content_is('CustomContext::Controller::Foo'); | ||
|
||
done_testing; | ||
|