relative-pathing.t 2.61 KB
Newer Older
1 2 3
use warnings;
use strict;

4
##############################################################################
5 6 7 8 9 10 11 12 13 14 15 16 17 18
package Wifty::UI::aliased_pkg;
use base qw/Template::Declare/;
use Template::Declare::Tags;

template 'relative'     => sub { show('local') };
template 'relative_dot' => sub { show('./local') };
template 'fullpath'     => sub { show('/aliased_pkg/local') };
template 'root'         => sub { show('/local') };
template 'parent'       => sub { show('../local') };

template 'local' => sub {
    div { outs( 'This is a template local to ' . __PACKAGE__ ) };
};

19
##############################################################################
20 21 22 23 24 25 26 27 28 29 30 31 32 33
package Wifty::UI;
use base qw/Template::Declare/;
use Template::Declare::Tags;

alias Wifty::UI::aliased_pkg under '/aliased_pkg';

template 'relative'     => sub { show('local') };
template 'relative_dot' => sub { show('./local') };
template 'root'         => sub { show('/local') };

template 'local' => sub {
    div { outs( 'This is a template local to ' . __PACKAGE__ ) };
};

34 35 36 37 38 39
# test '..' inside template name, not leading, may be it's rare, but people
# do crazy things
template 'up_level_inside/test'  => sub { show('local/../local') };
template 'up_level_inside/local' => sub { div { "This is up_level_inside/local" } };


40
##############################################################################
41 42
package main;
use Template::Declare::Tags;
43
Template::Declare->init( dispatch_to => ['Wifty::UI'] );
44

45
use Test::More tests => 25;
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

ok( Wifty::UI::aliased_pkg->has_template('local') );
ok( Wifty::UI->has_template('local') );
ok( Template::Declare->has_template('aliased_pkg/local') );

{
    my $simple = ( show('local') );
    like( $simple, qr'template local' );
    like( $simple, qr'Wifty::UI', 'Correct package');
}

{
    my $simple = ( show('aliased_pkg/local') );
    like( $simple, qr'template local' );
    like( $simple, qr'Wifty::UI::aliased_pkg', 'Correct package');
}

for my $template (qw(aliased_pkg/relative aliased_pkg/relative_dot aliased_pkg/fullpath)) {
    my $simple = ( show( $template ) );
    like( $simple, qr'template local' );
    like( $simple, qr'Wifty::UI::aliased_pkg', 'Correct package for '.$template);
}

for my $template (qw(aliased_pkg/root aliased_pkg/parent relative relative_dot root)) {
    my $simple = ( show( $template ) );
    like( $simple, qr'template local' );
    like( $simple, qr'Wifty::UI', 'Correct package for '.$template);
}

75 76 77 78 79 80 81 82 83 84
{
    my $simple = ( show('up_level_inside/test') );
    like( $simple, qr{This is up_level_inside/local} );
}

{
    my $simple = ( show('/up_level_inside/any/../local') );
    like( $simple, qr{This is up_level_inside/local} );
}

85
1;