File Coverage

blib/lib/Data/Tabular/Cell.pm
Criterion Covered Total %
statement 34 85 40.0
branch 9 46 19.5
condition 3 11 27.2
subroutine 11 17 64.7
pod 0 15 0.0
total 57 174 32.7


line stmt bran cond sub pod time code
1             # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved
2              
3 6     6   33 use strict;
  6         12  
  6         570  
4             package
5             Data::Tabular::Cell;
6              
7 6     6   34 use Carp qw(croak);
  6         19  
  6         19339  
8              
9             #use overload '""' => \&str;
10              
11             sub new
12             {
13 1259     1259 0 1800 my $class = shift;
14              
15 1259         4532 my $args = { @_ };
16              
17 1259 50       3639 die "No row" unless ref $args->{row};
18 1259 50 33     8953 die "No cell" unless ref $args->{cell} || defined $args->{cell};
19              
20 1259         2837 my $self = bless($args, $class);
21              
22 1259         4422 $self;
23             }
24              
25             sub row_id
26             {
27 440     440 0 574 my $self = shift;
28 440         848 $self->row->id() - 1;
29             }
30              
31             sub col_id
32             {
33 1344     1344 0 1876 my $self = shift;
34 1344         5795 $self->{id};
35             }
36              
37             sub row
38             {
39 440     440 0 502 my $self = shift;
40 440         1546 $self->{row};
41             }
42              
43             sub data
44             {
45 988     988 0 1416 my $self = shift;
46              
47 988         12469 my $ret = $self->{row}->get_column($self->{cell});
48              
49 988         2565 return $ret;
50             }
51              
52             sub str
53             {
54 0     0 0 0 my $self = shift;
55 0         0 die "STR " . caller;
56 0         0 'Cell : '. $self->{cell} . ' ' . $self->html_string;
57             }
58              
59             sub html_string
60             {
61 271     271 0 515 my $self = shift;
62              
63 271   100     1059 my $ret = $self->{row}->get_column($self->{cell}) || '';
64 271 100       743 if (my $type = ref($ret)) {
65 267 50       647 if ($type eq 'HASH') {
    50          
66 0   0     0 $ret = $ret->{html} || $ret->{text} || $ret->{data};
67             } elsif ($type eq 'ARRAY') {
68 0         0 die 'XXXXX';
69             } else {
70 267 50       995 if ($ret->can('bob')) {
71             # we just use it;
72             } else {
73             # we just use it;
74             }
75             }
76             } else {
77             # $ret;
78             }
79              
80 271 100       876 length($ret) ? $ret : ' '; # This is wrong FIXME
81             }
82              
83             sub colspan
84             {
85 288     288 0 374 my $self = shift;
86              
87 288         429 my $colspan = $self->{colspan};
88              
89 288         14478 return $colspan;
90             }
91              
92             sub html_attribute_string
93             {
94 0     0 0 0 my $self = shift;
95 0         0 my $row = $self->{row};
96 0         0 my $header = $self->{cell};
97 0         0 my $data = $self->{row}->get_column($self->{cell});
98 0         0 my $colspan = $self->{colspan};
99 0         0 warn join ' ', caller;
100 0         0 my $attributes = $row->cell_html_attributes($self);
101              
102 0 0       0 if ($colspan > 1) {
103 0         0 $attributes->{colspan} = $colspan,
104             }
105              
106 0 0       0 if (my $type = ref($data)) {
107 0 0       0 if ({
108             HASH => 1,
109             ARRAY => 1,
110             CODE => 1,
111             }->{$type}) {
112 0 0       0 if ($type eq 'HASH') {
113 0         0 $attributes->{bgcolor} = $data->{bgcolor};
114             }
115             # don't do anything
116             } else {
117 0 0       0 if ($data->can('attributes')) {
118 0         0 $attributes = {
119             %$attributes,
120 0         0 %{$data->attributes()},
121             }
122             } else {
123 0         0 warn 'no attributes ', ref($data);
124             }
125             }
126             }
127 0 0       0 if ($self->{bgcolor}) {
128 0         0 $attributes->{bgcolor} = $self->{bgcolor};
129             }
130              
131 0         0 my $ret = ''; # FIXME
132 0         0 for my $attribute (sort keys %$attributes) {
133 0 0       0 next unless defined($attributes->{$attribute});
134 0         0 $ret .= qq| $attribute="| . $attributes->{$attribute} . qq|"|;
135             }
136              
137 0         0 $ret;
138             }
139              
140             sub hdr
141             {
142 288     288 0 400 my $self = shift;
143 288         906 $self->{row}->hdr;
144             }
145              
146             sub name
147             {
148 0     0 0 0 my $self = shift;
149 0         0 my $cell = $self->{cell};
150              
151 0         0 $cell;
152             }
153              
154             sub xls_type
155             {
156 0     0 0 0 my $self = shift;
157              
158 0         0 my $cell = $self->{row}->get_column($self->{cell});
159 0         0 my $ret = 'text';
160 0 0       0 if (my $type = ref($cell)) {
161 0 0       0 if ($type eq 'HASH') {
    0          
162             } elsif ($type eq 'ARRAY') {
163             } else {
164 0 0       0 if ($cell->can('type')) {
165 0         0 $ret = $cell->type;
166             } else {
167             # we just use it;
168             }
169             }
170             }
171 0         0 $ret;
172             }
173              
174             sub xls_string
175             {
176 0     0 0 0 my $self = shift;
177              
178 0         0 my $ret = $self->{row}->get_column($self->{cell});
179 0 0       0 if (my $type = ref($ret)) {
180 0 0       0 if ($type eq 'HASH') {
    0          
181 0   0     0 $ret = $ret->{html} || $ret->{text};
182             } elsif ($type eq 'ARRAY') {
183 0         0 die 'XXXXX';
184             } else {
185 0 0       0 if ($ret->can('xls_data')) {
186             # we just use it;
187 0         0 $ret = $ret->xls_data();
188             } else {
189             # we just use it;
190             }
191             }
192             }
193 0         0 $ret;
194             }
195              
196             sub column_name
197             {
198 288     288 0 1080 my $self = shift;
199              
200 288         1090 $self->{cell};
201             }
202              
203             sub type
204             {
205 0     0 0   my $self = shift;
206              
207 0 0         $self->{type} || 'normal';
208             }
209              
210              
211             1;
212             __END__