/usr/share/perl5/Excel/Template/Context.pm is in libexcel-template-perl 0.34-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | package Excel::Template::Context;
use strict;
BEGIN {
use vars qw(@ISA);
@ISA = qw(Excel::Template::Base);
use Excel::Template::Base;
}
use Excel::Template::Format;
# This is a helper object. It is not instantiated by the user, nor does it
# represent an XML node. Rather, every container will use this object to
# maintain the context for its children.
my %isAbsolute = map { $_ => ~~1 } qw(
ROW
COL
);
sub new
{
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{ACTIVE_WORKSHEET} = undef;
$self->{FORMAT_OBJECT} = Excel::Template::Format->new;
$self->{ACTIVE_FORMAT} = $self->{FORMAT_OBJECT}->blank_format($self);
$self->{WORKSHEET_NAMES} = undef;
$self->{__MARKS} = {};
# Removed NAME_MAP until I figure out what the heck it's for
for (qw( STACK PARAM_MAP ))
{
next if defined $self->{$_} && ref $self->{$_} eq 'ARRAY';
$self->{$_} = [];
}
$self->{$_} = 0 for keys %isAbsolute;
return $self;
}
sub use_unicode { $_[0]->{UNICODE} && 1 }
sub _find_param_in_map
{
my $self = shift;
my ($map, $param, $depth) = @_;
$param = uc $param;
$depth ||= 0;
my ($val, $found);
for my $map (reverse @{$self->{$map}})
{
next unless exists $map->{$param};
$depth--, next if $depth;
$found = ~~1;
$val = $map->{$param};
last;
}
die "Parameter '$param' not found\n"
if !$found && $self->{DIE_ON_NO_PARAM};
return $val;
}
sub param
{
my $self = shift;
$self->_find_param_in_map(
'PARAM_MAP',
@_,
);
}
#sub named_param
#{
# my $self = shift;
# $self->_find_param_in_map(
# 'NAME_MAP',
# @_,
# );
#}
sub resolve
{
my $self = shift;
my ($obj, $key, $depth) = @_;
$key = uc $key;
$depth ||= 0;
my $obj_val = $obj->{$key};
$obj_val = $self->param($1)
if $obj_val =~ /^\$(\S+)$/o;
#GGG Remove this once NAME_MAP is working
# $obj_val = $self->named_param($1)
# if $obj_val =~ /^\\(\S+)$/o;
#GGG Does this adequately test values to make sure they're legal??
# A value is defined as:
# 1) An optional operator (+, -, *, or /)
# 2) A decimal number
#GGG Convert this to use //x
my ($op, $val) = $obj_val =~ m/^\s*([\+\*\/\-])?\s*([\d.]*\d)\s*$/oi;
# Unless it's a relative value, we have what we came for.
return $obj_val unless $op;
my $prev_val = $isAbsolute{$key}
? $self->{$key}
: $self->get($obj, $key, $depth + 1);
return $obj_val unless defined $prev_val;
return $prev_val unless defined $obj_val;
# Prevent divide-by-zero issues.
return $prev_val if $op eq '/' and $val == 0;
my $new_val;
for ($op)
{
/^\+$/ && do { $new_val = ($prev_val + $val); last; };
/^\-$/ && do { $new_val = ($prev_val - $val); last; };
/^\*$/ && do { $new_val = ($prev_val * $val); last; };
/^\/$/ && do { $new_val = ($prev_val / $val); last; };
die "Unknown operator '$op' in arithmetic resolve\n";
}
return $new_val if defined $new_val;
return;
}
sub enter_scope
{
my $self = shift;
my ($obj) = @_;
push @{$self->{STACK}}, $obj;
for my $key (keys %isAbsolute)
{
next unless exists $obj->{$key};
$self->{$key} = $self->resolve($obj, $key);
}
return ~~1;
}
sub exit_scope
{
my $self = shift;
my ($obj, $no_delta) = @_;
unless ($no_delta)
{
my $deltas = $obj->deltas($self);
$self->{$_} += $deltas->{$_} for keys %$deltas;
}
pop @{$self->{STACK}};
return ~~1;
}
sub get
{
my $self = shift;
my ($dummy, $key, $depth) = @_;
$depth ||= 0;
$key = uc $key;
return unless @{$self->{STACK}};
my $obj = $self->{STACK}[-1];
return $self->{$key} if $isAbsolute{$key};
my $val = undef;
my $this_depth = $depth;
foreach my $e (reverse @{$self->{STACK}})
{
next unless exists $e->{$key};
next if $this_depth-- > 0;
$val = $self->resolve($e, $key, $depth);
last;
}
$val = $self->{$key} unless defined $val;
return $val unless defined $val;
return $self->param($1, $depth) if $val =~ /^\$(\S+)$/o;
return $val;
}
sub active_format
{
my $self = shift;
$self->{ACTIVE_FORMAT} = $_[0]
if @_;
$self->{ACTIVE_FORMAT};
}
sub new_worksheet
{
my $self = shift;
my ($worksheet) = @_;
$self->{ROW} = $self->{COL} = 0;
$self->{REFERENCES} = {};
my $name = $self->get( $worksheet, 'NAME' );
if ( defined $name && length $name )
{
if ( exists $self->{WORKSHEET_NAMES}{$name} )
{
$name = '';
}
else
{
$self->{WORKSHEET_NAMES}{$name} = undef;
}
}
else
{
$name = '';
}
return $self->active_worksheet(
$self->{XLS}->add_worksheet( $name ),
);
}
sub mark
{
my $self = shift;
if ( @_ > 1 )
{
my %args = @_;
@{$self->{__MARKS}}{keys %args} = values %args;
}
return $self->{__MARKS}{$_[0]}
}
sub active_worksheet
{
my $self = shift;
$self->{ACTIVE_WORKSHEET} = $_[0]
if @_;
$self->{ACTIVE_WORKSHEET};
}
sub add_reference
{
my $self = shift;
my ($ref, $row, $col) = @_;
$self->{REFERENCES}{$ref} ||= [];
push @{$self->{REFERENCES}{$ref}}, [ $row, $col ];
return ~~1;
}
sub get_all_references
{
my $self = shift;
my $ref = uc shift;
$self->{REFERENCES}{$ref} ||= [];
return @{ $self->{REFERENCES}{$ref} };
}
sub get_last_reference
{
my $self = shift;
my $ref = uc shift;
$self->{REFERENCES}{$ref} ||= [];
return @{ $self->{REFERENCES}{$ref}[-1] };
}
sub format_object { $_[0]{FORMAT_OBJECT} }
1;
__END__
=head1 NAME
Excel::Template::Context - Excel::Template::Context
=head1 PURPOSE
This is a helper node that provides the global context for the nodes do their processing within. It provides attribute scoping, parameter resolution, and other very nice things.
Documentation is provided for if you wish to subclass another node.
=head1 NODE NAME
None
=head1 INHERITANCE
None
=head1 ATTRIBUTES
None
=head1 CHILDREN
None
=head1 AFFECTS
Everything
=head1 DEPENDENCIES
None
=head1 METHODS
=head2 active_format
=head2 active_worksheet
=head2 add_reference
=head2 format_object
=head2 get
=head2 get_all_references
=head2 get_last_reference
=head2 mark
=head2 new_worksheet
=head2 param
=head2 use_unicode
=head1 AUTHOR
Rob Kinyon (rob.kinyon@gmail.com)
=head1 SEE ALSO
=cut
|