Finished changes for v0.21 - including documentation fixes and a new renderer
[p5sagit/Excel-Template.git] / lib / Excel / Template / TextObject.pm
1 package Excel::Template::TextObject;
2
3 use strict;
4
5 BEGIN {
6     use vars qw(@ISA);
7     @ISA = qw(Excel::Template::Base);
8
9     use Excel::Template::Base;
10 }
11
12 # This is a helper object. It is not instantiated by the user,
13 # nor does it represent an XML object. Rather, certain elements,
14 # such as <textbox>, can use this object to do text with variable
15 # substitutions.
16
17 sub new
18 {
19     my $class = shift;
20     my $self = $class->SUPER::new(@_);
21
22     $self->{STACK} = []
23         unless defined $self->{STACK} &&
24             UNIVERSAL::isa($self->{STACK}, 'ARRAY');
25
26     return $self;
27 }
28
29 sub resolve
30 {
31     my $self = shift;
32     my ($context) = @_;
33
34     my $use_unicode = $context->use_unicode;
35
36     my $t;
37     if ($use_unicode)
38     {
39         require Unicode::String;
40         $t = Unicode::String::utf8('');
41     }
42     else
43     {
44         $t = '';
45     }
46
47     for my $tok (@{$self->{STACK}})
48     {
49         my $val = $tok;
50         $val = $val->resolve($context)
51             if Excel::Template::Factory::is_embedded( $val );
52
53         $t .= $use_unicode
54             ? Unicode::String::utf8("$val")
55             : $val;
56     }
57
58     return $t;
59 }
60
61 1;
62 __END__
63
64 =head1 NAME
65
66 Excel::Template::TextObject
67
68 =head1 PURPOSE
69
70 =head1 NODE NAME
71
72 =head1 INHERITANCE
73
74 =head1 ATTRIBUTES
75
76 =head1 CHILDREN
77
78 =head1 AFFECTS
79
80 =head1 DEPENDENCIES
81
82 =head1 USAGE
83
84 =head1 AUTHOR
85
86 Rob Kinyon (rob.kinyon@gmail.com)
87
88 =head1 SEE ALSO
89
90 =cut