File: 18_objects.t

package info (click to toggle)
libhtml-template-compiled-perl 1.003-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 772 kB
  • sloc: perl: 4,759; makefile: 5
file content (83 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
75
76
77
78
79
80
81
82
83

use Test::More tests => 4;
use strict;
use warnings;
local $Data::Dumper::Indent = 1; local $Data::Dumper::Sortkeys = 1;
BEGIN { use_ok('HTML::Template::Compiled') };
my $cache = File::Spec->catfile('t', 'cache');

{
	my $htc = HTML::Template::Compiled->new(
		scalarref => \<<'EOM',
<tmpl_var outer.get_content>
<tmpl_with outer>
    <tmpl_var get_content>
</tmpl_with>
<tmpl_with foo>
    <tmpl_var inner.get_content>
    <tmpl_var outer.get_content>
</tmpl_with>
EOM
		debug => 0,
        global_vars => 1,
	);
    my $object = bless {
        content => 23,
    }, "HTC_Dummy";
	$htc->param(
        outer => $object,
        foo => {
            inner => $object,
        },
	);
	my $out = $htc->output;
	$out =~ tr/\n\r //d;
    #print $out,$/;
    cmp_ok($out, "eq", 23 x 4, "global objects");
}

eval { require Scalar::Util };
my $scalar_util = $@ ? 0 : 1;
SKIP: {
	skip "no Scalar::Util", 2 unless $scalar_util;

    for my $strict (qw/ strict nostrict/) {
        my $htc = HTML::Template::Compiled->new(
            scalarref => \<<'EOM',
            <%= object.get_content %>
            <%= object.dummy %>
            <%= hash.key %>
EOM
            debug => 0,
            global_vars => 1,
            objects => $strict,
            cache => 0,
        );
        my $object = bless {
            content => 23,
        }, "HTC_Dummy";
        $htc->param(
            object => $object,
            hash => {
                key => 42,
            },
        );
        my $out = '';
        eval {
            $out = $htc->output;
        };
        #warn __PACKAGE__.':'.__LINE__.": error: $@\n";
        $out =~ s/\s+//g;
        #print $out,$/;
        if ($strict eq 'strict') {
            cmp_ok($@, "=~", q/Can't locate object method "dummy"/ , "global objects '$strict'");
        }
        else {
            cmp_ok($out, "eq", 2342, "global objects '$strict'");
        }
    }
}

sub HTC_Dummy::get_content {
    return $_[0]->{content};
}