1
package PDF::FromHTML::Template::Container::Conditional;
3
#GGG Convert <conditional> to be a special case of <switch>?
9
@ISA = qw(PDF::FromHTML::Template::Container);
11
use PDF::FromHTML::Template::Container;
16
(map { $_ => $_ } ( '>', '<', '==', '!=', '>=', '<=' )),
17
(map { $_ => $_ } ( 'gt', 'lt', 'eq', 'ne', 'ge', 'le' )),
20
# This cannot be within a should_render() function because the conditional needs
21
# to return true even if the conditional is false. We are indicating that this
22
# branch has done everything it needs to do, not that this branch is calling for
25
sub conditional_passes
30
my $name = $context->get($self, 'NAME');
31
return 0 unless $name =~ /\S/;
33
my $val = $context->param($name);
34
$val = @{$val} while UNIVERSAL::isa($val, 'ARRAY');
35
$val = ${$val} while UNIVERSAL::isa($val, 'SCALAR');
37
my $istrue = (defined $val && $val) ? 1 : 0;
38
my $value = $context->get($self, 'VALUE');
41
my $op = $context->get($self, 'OP');
42
$op = defined $op && exists $isOp{$op}
49
/^>$/ && do { $res = ($val > $value); last };
50
/^<$/ && do { $res = ($val < $value); last };
51
/^==$/ && do { $res = ($val == $value); last };
52
/^!=$/ && do { $res = ($val != $value); last };
53
/^>=$/ && do { $res = ($val >= $value); last };
54
/^<=$/ && do { $res = ($val <= $value); last };
55
/^gt$/ && do { $res = ($val gt $value); last };
56
/^lt$/ && do { $res = ($val lt $value); last };
57
/^eq$/ && do { $res = ($val eq $value); last };
58
/^ne$/ && do { $res = ($val ne $value); last };
59
/^ge$/ && do { $res = ($val ge $value); last };
60
/^le$/ && do { $res = ($val le $value); last };
62
die "Unknown operator '$op' in conditional resolve", $/;
67
elsif (my $is = uc $context->get($self, 'IS'))
75
warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/
90
return 0 unless $self->should_render($context);
92
return 1 unless $self->conditional_passes($context);
94
return $self->iterate_over_children($context);
100
my ($context, $attr) = @_;
102
return 0 unless $self->conditional_passes($context);
104
return $self->SUPER::max_of($context, $attr);
110
my ($context, $attr) = @_;
112
return 0 unless $self->conditional_passes($context);
114
return $self->SUPER::total_of($context, $attr);
120
return unless $self->conditional_passes(@_);
121
return $self->SUPER::_do_page( @_ );
126
_do_page(@_,'begin_page');
131
_do_page(@_,'end_page');
139
PDF::FromHTML::Template::Container::Conditional
143
To conditionally allow children to render
148
IF (an alias for CONDITIONAL)
152
PDF::FromHTML::Template::Container
158
=item * NAME - Required. This is a parameter name, whose value will determine
159
if the conditional passed or fails. If NAME is not specified, the conditional
160
will consider to always fail.
162
=item * OP - defaults to == (numeric equality). If VALUE is specified, this will
163
be how NAME and VALUE are compared. OP can be any of the 6 numeric comparision
164
operators or the 6 string comparision operators.
166
=item * VALUE - if this is specified, OP will be checked. This is a standard
167
attribute, so if you want a parameter, prepend it with '$'.
169
=item * IS - If there is no VALUE attribute, this will be checked. IS can be
170
either 'FALSE' or 'TRUE'. The boolean of NAME will be compared and the
171
conditional will branch appropriately. If NAME has no value, this will fail.
173
=item * NONE - If there is no IS and no VALUE, then an attempt will be made to
174
find the variable defined by NAME. If it exists and is true, the condition
175
will succeed. Otherwise, it will fail.
193
<if name="__PAGE__" OP="!=" VALUE="__LAST_PAGE__">
194
... Children execute if the current page is not the last page ...
197
<if name="Param1" OP="eq" VALUE="$Param2">
198
... Children execute if Param1 is string-wise equals to Param2 ...
203
Rob Kinyon (rkinyon@columbus.rr.com)