File: magic.t

package info (click to toggle)
libhtml-template-pro-perl 0.9524-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,512 kB
  • sloc: ansic: 1,841; perl: 1,474; yacc: 404; pascal: 118; makefile: 6
file content (95 lines) | stat: -rw-r--r-- 1,515 bytes parent folder | download | duplicates (5)
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
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl -w

use Test::More;
use HTML::Template::Pro;

eval "require Tie::Hash";
if ($@) {
    plan skip_all => "Tie::Hash is required for testing POD";
    exit;
}
eval "require Tie::Array";
if ($@) {
    plan skip_all => "Tie::Array is required for testing POD";
    exit;
}
else {
    $tests=2;
    plan tests => $tests;
}

my %plainhash;
tie %plainhash, 'TestHash1';
my @plainarray;
tie @plainarray, 'TestArray';

my $t = HTML::Template::Pro->new( filename => 'templates-Pro/test_loop2.tmpl' , 
				  debug=>0,
				  case_sensitive => 1,
    );

$t->param('HASHREF1' => [ \%plainhash] );
ok($t->output =~/MAGIC1/);

$t->param('HASHREF1' => \@plainarray );
my $out=$t->output();
ok($out =~/MAGIC1/ && $out =~/MAGIC2/);
#$t->output();

package TestHash1;
use vars qw/@ISA/;
@ISA = 'Tie::StdHash';
require Tie::Hash;

sub TIEHASH  {
    my $none;
    my $storage = bless \$none, shift;
    $storage
}

sub FETCH    {
    return 'MAGIC1';
}

package TestHash2;
use vars qw/@ISA/;
@ISA = 'Tie::StdHash';
require Tie::Hash;

sub TIEHASH  {
    my $storage = bless {}, shift;
    $storage
}

sub FETCH    {
    return 'MAGIC2';
}

package TestArray;
use vars qw/@ISA $count/;
@ISA = ('Tie::StdArray');
require Tie::Array;

BEGIN {
$count = 0;
}

sub TIEARRAY  {
    my $none;
    my $storage = bless \$none, shift;
    $storage
}

sub FETCHSIZE {
    return 2;
}

sub FETCH {
    my %myhash;
    if ($count++==0) {
	tie %myhash, 'TestHash1';
    } else {
	tie %myhash, 'TestHash2';
    }
    return \%myhash;
}