File Coverage

blib/lib/Data/Tabular/Config/Output.pm
Criterion Covered Total %
statement 43 86 50.0
branch 8 28 28.5
condition 3 13 23.0
subroutine 11 21 52.3
pod 0 19 0.0
total 65 167 38.9


line stmt bran cond sub pod time code
1             # Copyright (C) 2003-2007, G. Allen Morris III, all rights reserved
2              
3 7     7   40 use strict;
  7         12  
  7         1375  
4             package Data::Tabular::Config::Output;
5              
6             sub new
7             {
8 10     10 0 36 my $caller = shift;
9 10   33     71 my $class = ref($caller) || $caller;
10              
11 10         57 my $self = bless { @_ }, $class;
12 10         102 $self->{caller} = join(':', caller);
13              
14 10   50     202 $self->{xls} ||= {};
15 10   50     82 $self->{html} ||= {};
16              
17 10 50       52 if ($self->{titles}) {
18 0         0 for my $column (keys %{$self->{titles}}) {
  0         0  
19 0 0 0     0 if ($self->{columns}{$column}{title} and $self->{columns}{$column}{title} ne $self->{titles}->{$column}) {
20 7     7   29543 use Data::Dumper;
  7         99682  
  7         10058  
21 0         0 die Dumper $self;
22             }
23 0         0 $self->{columns}{$column}{title} = $self->{titles}->{$column};
24             }
25             }
26              
27 10 50       49 die 'No column list' unless $self->column_list;
28 10         33 $self;
29             }
30              
31             sub column_list
32             {
33 10     10 0 20 my $self = shift;
34 10 50       65 wantarray ? @{$self->{headers}} : $self->{headers};
  0         0  
35             }
36              
37             sub col_id
38             {
39 0     0 0 0 my $self = shift;
40 0         0 my $col_name = shift;
41              
42 0         0 my $x = 0;
43 0         0 for my $col ($self->column_list) {
44 0 0       0 if ($col eq $col_name) {
45 0         0 return $x;
46             }
47 0         0 $x++;
48             }
49 0         0 die "Unknown column $col_name";
50             }
51              
52             sub title
53             {
54 102     102 0 129 my $self = shift;
55 102         120 my $column_name = shift;
56 102 100       798 $self->{columns}->{$column_name}->{title} || $column_name;
57             }
58              
59             sub html_column_attributes
60             {
61 0     0 0 0 my $self = shift;
62 0         0 my $column_name = shift;
63 0 0       0 my $ret = {
64 0         0 %{$self->{columns}->{$column_name}->{html_attributes} || {}},
65             };
66 0         0 $ret->{align} = 'right';
67 0 0       0 if (my $width = $self->{columns}->{$column_name}->{width}) {
68 0 0       0 die if defined $ret->{width};
69 0         0 $ret->{width} = $width;
70             }
71 0         0 return $ret;
72             }
73              
74             sub xls_width
75             {
76 0     0 0 0 my $self = shift;
77 0         0 my $column_name = shift;
78 0 0 0     0 $self->{columns}->{$column_name}->{xls}->{width} || $self->{xls}->{width} || 10;
79             }
80              
81             sub xls_title_format
82             {
83 0     0 0 0 my $self = shift;
84 0         0 my $column_name = shift;
85              
86 0         0 $self->{columns}->{$column_name}->{xls}->{title_format};
87             }
88              
89             sub align
90             {
91 0     0 0 0 my $self = shift;
92 0         0 my $column_name = shift;
93 0         0 $self->{columns}->{$column_name}->{align};
94             }
95              
96             sub headers
97             {
98 262     262 0 496 my $self = shift;
99              
100 262         338 @{$self->{headers}};
  262         1687  
101             }
102              
103             sub html_attribute_string
104             {
105 2     2 0 4 my $self = shift;
106 2         9 my $attributes = {
107             border => 1,
108             };
109 2         6 my $na = $self->{html}->{attributes};
110 2         13 for my $attribute (sort keys %$na) {
111 0         0 $attributes->{$attribute} = $na->{$attribute};
112             }
113              
114 2         6 my $ret = '';
115 2         9 for my $attribute (sort keys %$attributes) {
116 2 50       10 next unless $attributes->{$attribute};
117 2         12 $ret .= qq| $attribute="| . $attributes->{$attribute} . qq|"|;
118             }
119              
120 2         11 $ret;
121             }
122              
123             sub test_xls_attribute
124             {
125 3     3 0 7 my $self = shift;
126 3         10 my $attribute = shift;
127 3         543 return $self->{xls}->{$attribute};
128             }
129              
130             sub table
131             {
132 0     0 0 0 shift->{title};
133             }
134              
135             sub set_type
136             {
137 6     6 0 26 my $self = shift;
138 6         19 my $args = { @_ };
139              
140 6         18 $self->{types}->{$args->{name}} = $args->{type};
141              
142 6         15 undef;
143             }
144              
145             sub type
146             {
147 320     320 0 386 my $self = shift;
148 320         361 my $name = shift;
149              
150 320 100       1734 $self->{types}->{$name} || 'text';
151             }
152              
153             sub set_column_format
154             {
155 0     0 0 0 my $self = shift;
156 0         0 my %args = @_;
157              
158 0         0 for my $key (keys %args) {
159 0         0 $self->{format}{$key} = $args{$key};
160             }
161             }
162              
163             sub get_column_format
164             {
165 0     0 0 0 my $self = shift;
166 0 0       0 my $column = shift or die 'need name';
167              
168 0 0       0 $self->{format}{$column} || '%s';
169             }
170              
171             sub format
172             {
173 102     102 0 373 'bob';
174             }
175              
176             sub set_use_functions
177             {
178 0     0 0   warn "set_use_functions";
179             }
180              
181             sub get_use_functions
182             {
183 0     0 0   warn "get_use_functions";
184             }
185              
186             1;
187             __END__