Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests for overriding controllers

  • Loading branch information...
commit 5bd095407403792036e14e28f366cdeaf56b054c 1 parent cde2635
Zbigniew Lukasiak authored
View
2  lib/WebNano.pm
@@ -7,7 +7,7 @@ use WebNano::FindController 'find_nested';
use Plack::Response;
use Scalar::Util qw(blessed);
-use Object::Tiny::RW 'renderer';
+use Object::Tiny::RW qw( renderer DEBUG );
use Encode;
sub psgi_callback {
View
2  lib/WebNano/Controller.pm
@@ -9,6 +9,8 @@ use Plack::Request;
use Object::Tiny::RW qw/ app env self_url url_map _req /;
+sub DEBUG { shift->app->DEBUG }
+
sub req {
my $self = shift;
return $self->_req if defined $self->_req;
View
2  lib/WebNano/DirController.pm
@@ -19,11 +19,13 @@ sub handle {
my $self = $class->new( %args );
my $out = $self->local_dispatch( $path );
return $out if $out;
+ warn "No local action found in $class\n" if $self->DEBUG;
my( $path_part, $new_path ) = ( $path =~ qr{^([^/]*)/?(.*)} );
$path_part =~ s/::|'//g if defined( $path_part );
return if !length( $path_part );
my $controller_class = find_nested( $class->_self_path . $path_part, $args{app}->controller_search_path );
return if !$controller_class;
+ warn "Dispatching to $controller_class\n" if $self->DEBUG;
return $controller_class->handle(
%args,
path => $new_path,
View
13 t/11.subclass.t
@@ -56,4 +56,17 @@ test_psgi(
}
);
+test_psgi(
+ app => SubClassApp->new()->psgi_callback,
+ client => sub {
+ my $cb = shift;
+ my $res = $cb->(GET "ToBeOverridden/some");
+ is( $res->content, 'SubClassApp::Controller::ToBeOverridden', 'overridden controller' );
+ $res = $cb->(GET "ToBeOverridden/other");
+ is( $res->code, 404 , 'actions are not merged' );
+ $res = $cb->(GET "ToBeOverridden/templated");
+ is( $res->content, "t/data/templates/ToBeOverridden/templated\n", 'templates are independent' );
+ }
+);
+
done_testing();
View
1  t/data/templates/ToBeOverridden/templated
@@ -0,0 +1 @@
+t/data/templates/ToBeOverridden/templated
View
12 t/lib/MyApp/Controller/ToBeOverridden.pm
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+
+package MyApp::Controller::ToBeOverridden;
+use base 'WebNano::Controller';
+
+sub some_action { return __PACKAGE__ };
+
+sub other_action { return __PACKAGE__ };
+
+1;
+
View
12 t/lib/SubClassApp/Controller/ToBeOverridden.pm
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+
+package SubClassApp::Controller::ToBeOverridden;
+use base 'WebNano::Controller';
+
+sub some_action { return __PACKAGE__ };
+
+sub templated_action { return shift->render() }
+
+1;
+
View
5 t/subclass.psgi
@@ -0,0 +1,5 @@
+use SubClassApp;
+my $app = SubClassApp->new( DEBUG => 1 );
+$app->psgi_callback;
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.