- Fixed Makefile.PL so that it uses PM_FILTER instead of rolling its own
[p5sagit/Excel-Template.git] / lib / Excel / Template / Element / Cell.pm
1 package Excel::Template::Element::Cell;
2
3 use strict;
4
5 BEGIN {
6     use vars qw(@ISA);
7     @ISA = qw(Excel::Template::Element);
8
9     use Excel::Template::Element;
10 }
11
12 sub new
13 {
14     my $class = shift;
15     my $self = $class->SUPER::new(@_);
16                                                                                 
17     $self->{TXTOBJ} = Excel::Template::Factory->create('TEXTOBJECT');
18                                                                                 
19     return $self;
20 }
21
22 sub get_text
23 {
24     my $self = shift;
25     my ($context) = @_;
26                                                                                 
27     my $txt = $context->get($self, 'TEXT');
28     if (defined $txt)
29     {
30         my $txt_obj = Excel::Template::Factory->create('TEXTOBJECT');
31         push @{$txt_obj->{STACK}}, $txt;
32         $txt = $txt_obj->resolve($context);
33     }
34     elsif ($self->{TXTOBJ})
35     {
36         $txt = $self->{TXTOBJ}->resolve($context)
37     }
38     else
39     {
40 UNI_YES        $txt = Unicode::String::utf8('');
41 UNI_NO         $txt = '';
42     }
43                                                                                 
44     return $txt;
45 }
46
47 sub render
48 {
49     my $self = shift;
50     my ($context, $method) = @_;
51
52     $method ||= 'write';
53
54     my ($row, $col) = map { $context->get($self, $_) } qw(ROW COL);
55
56     my $ref = uc $context->get( $self, 'REF' );
57     if (defined $ref && length $ref)
58     {
59         $context->add_reference( $ref, $row, $col );
60     }
61
62     $context->active_worksheet->$method(
63         $row, $col,
64         $self->get_text($context),
65         $context->active_format,
66     );
67
68     return 1;
69 }
70
71 sub deltas
72 {
73     return {
74         COL => +1,
75     };
76 }
77
78 1;
79 __END__
80
81 =head1 NAME
82
83 Excel::Template::Element::Cell - Excel::Template::Element::Cell
84
85 =head1 PURPOSE
86
87 To actually write stuff to the worksheet
88
89 =head1 NODE NAME
90
91 CELL
92
93 =head1 INHERITANCE
94
95 Excel::Template::Element
96
97 =head1 ATTRIBUTES
98
99 =over 4
100
101 =item * TEXT
102
103 This is the text to write to the cell. This can either be text or a parameter
104 with a dollar-sign in front of the parameter name.
105
106 =item * COL
107
108 Optionally, you can specify which column you want this cell to be in. It can be
109 either a number (zero-based) or an offset. See Excel::Template for more info on
110 offset-based numbering.
111
112 =item * REF
113
114 Adds the current cell to the a list of cells that can be backreferenced.
115 This is useful when the current cell needs to be referenced by a
116 formula. See BACKREF and RANGE.
117
118 =back 4
119
120 There will be more parameters added, as features are added.
121
122 =head1 CHILDREN
123
124 Excel::Template::Element::Formula
125
126 =head1 EFFECTS
127
128 This will consume one column on the current row. 
129
130 =head1 DEPENDENCIES
131
132 None
133
134 =head1 USAGE
135
136   <cell text="Some Text Here"/>
137   <cell>Some other text here</cell>
138
139   <cell text="$Param2"/>
140   <cell>Some <var name="Param"> text here</cell>
141
142 In the above example, four cells are written out. The first two have text hard-
143 coded. The second two have variables. The third and fourth items have another
144 thing that should be noted. If you have text where you want a variable in the
145 middle, you have to use the latter form. Variables within parameters are the
146 entire parameter's value.
147
148 Please see Spreadsheet::WriteExcel for what constitutes a legal formula.
149
150 =head1 AUTHOR
151
152 Rob Kinyon (rob.kinyon@gmail.com)
153
154 =head1 SEE ALSO
155
156 ROW, VAR, FORMULA
157
158 =cut