Permalink
Browse files

no self_path attribute

  • Loading branch information...
Zbigniew Lukasiak
Zbigniew Lukasiak committed Aug 28, 2010
1 parent 37ec415 commit 8f9597ef974f3cca069bdab5b7c571f60e6ce401
@@ -38,8 +38,10 @@ sub render {
my $c = $params{c};
my @input_path;
if( $c ){
- @input_path = $c->self_path;
- push @input_path, @{ $c->template_search_path } if $c->template_search_path;
+ my $path = ref $c;
+ $path =~ s/.*::Controller(::)?//;
+ $path =~ s{::}{/};
+ @input_path = ( $path, @{ $c->template_search_path });
}
if( !@input_path ){
@input_path = ( '' );
@@ -4,9 +4,15 @@ use lib 't/lib';
use lib 'extensions/lib';
use WebNano::Renderer::TT;
{
- package TestController;
+ package MyApp::Controller::subdir1;
+ use base 'WebNano::Controller';
+
+ sub template_search_path { [ 'subdir2' ] }
+}
+
+{
+ package MyApp::Controller::subdir2;
use base 'WebNano::Controller';
- use Object::Tiny::RW 'template_search_path';
}
my $renderer = WebNano::Renderer::TT->new( root => [ 't/data/tt2' ] );
@@ -20,22 +26,22 @@ is( $out, "tt1/some_template.tt\n" );
$out = $renderer->render( template => 'second_root.tt' );
is( $out, "tt2/second_root.tt\n" );
-my $c = TestController->new( self_path => 'subdir1', template_search_path => [ 'subdir2' ] );
+my $c = MyApp::Controller::subdir1->new();
$out = $renderer->render( c => $c, template => 'template.tt' );
is( $out, "tt1/subdir1/template.tt\n" );
-my $c = TestController->new( self_path => 'subdir2' );
+my $c = MyApp::Controller::subdir2->new();
$out = $renderer->render( c => $c, template => 'template.tt' );
is( $out, "tt1/subdir2/template.tt\n" );
-my $c = TestController->new( self_path => 'subdir1', template_search_path => [ 'subdir2' ] );
+my $c = MyApp::Controller::subdir1->new();
$out = $renderer->render( c => $c, template => 'template1.tt' );
is( $out, "tt1/subdir2/template1.tt\n" );
$out = $renderer->render( c => $c, template => 'second_root.tt' );
is( $out, "tt2/subdir1/second_root.tt\n" );
-my $c = TestController->new( self_path => 'subdir2' );
+my $c = MyApp::Controller::subdir2->new();
$out = $renderer->render( c => $c, template => 'second_root.tt' );
is( $out, "tt2/subdir2/second_root.tt\n" );
-my $c = TestController->new( self_path => 'subdir1', template_search_path => [ 'subdir2' ] );
+my $c = MyApp::Controller::subdir1->new();
$out = $renderer->render( c => $c, template => 'second_root1.tt' );
is( $out, "tt2/subdir2/second_root1.tt\n" );
View
@@ -32,7 +32,6 @@ sub handle {
application => $self,
env => $env,
self_url => '/',
- self_path => '/',
);
if( not defined $out ){
my $res = Plack::Response->new(404);
View
@@ -9,7 +9,7 @@ use URI::Escape 'uri_unescape';
use Plack::Request;
use File::Spec::Functions qw/catfile catdir/;
-use Object::Tiny::RW qw/ application env self_path self_url url_map _request /;
+use Object::Tiny::RW qw/ application env self_url url_map _request /;
sub request {
my $self = shift;
@@ -26,6 +26,14 @@ sub render {
return $self->application->renderer->render( c => $self, @_ );
}
+sub self_path{
+ my $self = shift;
+ my $path = ref $self;
+ $path =~ s/.*::Controller(::)?//;
+ $path =~ s{::}{/};
+ return $path . '/';
+}
+
sub external_dispatch {
my ( $self, $path ) = @_;
my( $path_part, $new_path ) = ( $path =~ qr{^([^/]*)/?(.*)} );
@@ -36,7 +44,6 @@ sub external_dispatch {
return $controller_class->handle(
path => $new_path,
self_url => $self->self_url . $path_part . '/',
- self_path => $self->self_path. $path_part . '/',
env => $self->env,
application => $self->application,
);
View
@@ -10,12 +10,6 @@ use File::Copy;
use WebNano::Renderer::TTiny;
use WebNano::Controller;
-my $c = WebNano::Controller->new( self_path => '', template_search_path => [] );
-my $renderer = WebNano::Renderer::TTiny->new( root => 't/data/templates', application => WebNano->new() );
-my $rendered = $renderer->render( c => $c, template => 'dummy_template', some_var => 'some value' );
-ok( $rendered =~ /some_var: some value/, 'vars' );
-ok( $rendered =~ /^Some text/, 'Slurping template file' );
-
test_psgi(
app => MyApp->new()->psgi_callback,
client => sub {

0 comments on commit 8f9597e

Please sign in to comment.