-
Notifications
You must be signed in to change notification settings - Fork 12
/
Container.pm
128 lines (82 loc) · 2 KB
/
Container.pm
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package Template::Flute::Container;
use strict;
use warnings;
=head1 NAME
Template::Flute::Container - Container object for Template::Flute templates.
=head1 CONSTRUCTOR
=head2 new
Creates Template::Flute::Container object.
=cut
use Template::Flute::Expression;
# Constructor
sub new {
my ($class, $sob, $spec, $name) = @_;
my ($self);
$class = shift;
$self = {sob => $sob};
bless $self;
return $self;
}
=head1 METHODS
=head2 name
Returns name of the container.
=cut
sub name {
my ($self) = @_;
return $self->{sob}->{name};
}
=head2 set_values
Passes current values to this container.
=cut
sub set_values {
my ($self, $values) = @_;
$self->{values} = $values;
}
=head2 elt
Returns corresponding HTML template element of the list.
=cut
sub elt {
my ($self) = @_;
return $self->{sob}->{elts}->[0];
}
=head2 visible
Determines whether the container is visible. Possible return values are 1 (visible),
0 (hidden) or undef if the specification for the container misses a value attribute.
=cut
# visible
sub visible {
my ($self) = @_;
my ($key, $ret);
if ($key = $self->{sob}->{value}) {
# check whether this is an expression or a simple value
if ($key =~ /^\w[0-9\w_-]*$/) {
if (exists $self->{values}) {
if ($self->{values}->{$key}) {
return 1;
}
return 0;
}
return undef;
}
else {
$self->{_expr_parser} ||= Template::Flute::Expression->new($key);
$ret = $self->{_expr_parser}->evaluate($self->{values});
if ($ret) {
return 1;
}
return 0;
}
}
# container is visible if no value is specified
return 1;
}
=head1 AUTHOR
Stefan Hornburg (Racke), <racke@linuxia.de>
=head1 LICENSE AND COPYRIGHT
Copyright 2010-2011 Stefan Hornburg (Racke) <racke@linuxia.de>.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1;