Thread HTML::Template::Compiled (HTC) (209 answers)
Opened by renee at 2005-06-26 15:48

esskar
 2006-05-05 09:38
#40864 #40864
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
es ist kein guter Programmier-Stiel

Code: (dl )
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
package Animal;

sub new {
return bless {}, shift;
}

sub to_string {
die "pure virtual\n";
}

1;

package Animal::Dog;

use base qw/Animal/;

sub to_string {
return "Hund";
}

1;

package Animal::Cat;

use base qw/Animal/;

sub to_string {
return "Katze";
}

1;

package Animal::Mouse;

use base qw/Animal/;

sub to_string {
return "Maus";
}

1;

package Animal::Farm;

sub new {
return bless {}, shift;
}

sub add {
my $self = shift;
if(@_ > 1) {
$self->add($_) foreach @_;
} else {
my $animal = shift;
die "Is not an animal!" unless $animal->isa('Animal');
$self->{animals} ||= [];
push @{ $self->{animals} }, $animal;
}
}

sub to_string {
my $self = shift;
$self->{animals} ||= [];
return join ' ', map { $_->to_string } @{ $self->{animals} };
}

1;

# hier beginnt das script

#!/usr/bin/perl

use strict;

my $farm = Animal::Farm->new;
$farm->add(Animal::Dog->new);
$farm->add(Animal::Cat->new, Animal::Mouse->new);

my $template = HTML::Template::Compiled->new (
filename => $tmpl_file,
path => $mein_pfad,
use_query => 1
);

$template->param( farm => $farm );


im Template

Code: (dl )
<%= farm.to_string %>


HTH

PS: ungetestet

View full thread HTML::Template::Compiled (HTC)