File Coverage

blib/lib/DataCube/Cube/Style/HTML.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


\n"; \n" for @$row; \n";
line stmt bran cond sub pod time code
1              
2              
3              
4             package DataCube::Cube::Style::HTML;
5              
6 1     1   5 use strict;
  1         2  
  1         34  
7 1     1   4 use warnings;
  1         1  
  1         24  
8              
9 1     1   508 use DateTime;
  0            
  0            
10             use DataCube::Cube::Style::HTML::CSS;
11              
12              
13             sub new {
14             my($class,%opts) = @_;
15             bless { %opts }, ref($class) || $class;
16             }
17              
18             sub html {
19             my($self,$cube) = @_;
20             my $html = "";
21             $html .= $self->start_html($cube);
22             $html .= $self->start_body($cube);
23             $html .= $self->top_section($cube);
24            
25             $html .= $self->start_details($cube);
26             $html .= $self->details($cube);
27             $html .= $self->end_details($cube);
28              
29             $html .= $self->end_body($cube);
30             $html .= $self->end_html($cube);
31             return $html;
32             }
33              
34             sub html_from_table {
35             my($self,$cube,@table) = @_;
36            
37             my $html = "";
38            
39             $html .= $self->start_html($cube);
40             $html .= $self->start_body($cube);
41             $html .= $self->top_section($cube,@table);
42            
43             $html .= $self->start_details($cube);
44             $html .= $self->details_from_table($cube,@table);
45             $html .= $self->end_details($cube);
46              
47             $html .= $self->end_body($cube);
48             $html .= $self->end_html($cube);
49              
50             return $html;
51              
52             }
53              
54             sub start_html {
55             my($self,$cube) = @_;
56             my $style = DataCube::Cube::Style::HTML::CSS->new;
57              
58             my $html = '
59            
60            
61            
62            
63             Cube Report';
64            
65             $html .= $style->css;
66             $html .= '';
67             return $html;
68             }
69              
70             sub end_html {
71             my($self,$cube) = @_;
72             my $html = '';
73             return $html;
74             }
75              
76             sub start_body {
77             my($self,$cube) = @_;
78             my $html = '';
79             return $html;
80             }
81              
82             sub end_body {
83             my($self,$cube) = @_;
84             my $dt = DateTime->now;
85             my $year = $dt->year;
86             my $html = '
87            
88            

89            
90             Cube Report Generated by Project Codenamed "Blackbear"
91            
92             Copyright (C) 2009-' . $year . ' David Williams
93            
94            
95             ';
96             return $html;
97             }
98              
99             sub top_section {
100             my($self,$cube,@table) = @_;
101             my $time = scalar(localtime());
102             my $rows = @table ? $#table : scalar(keys %{$cube->{cube}});
103             my $schema = $cube->schema;
104             my $dim_count = $schema->field_count;
105             my $mea_count = $schema->measure_count;
106             my $html = "
107            

Cube Report

108            

109            
110             Report Generated at: $time
111            
112            
113            

";
114            
115             $html .= "
116            
117            
118             Cube Report Summary
119            
120            
121              
122              
123            
124            
125            
126             Rows 
127              $rows
128            
129            
130             Measures 
131              $mea_count
132            
133            
134             Dimensions 
135              $dim_count
136            
137            
138            
139            
";
140             return $html;
141             }
142              
143             sub start_details {
144             my($self,$cube) = @_;
145             my $schema = $cube->schema;
146             my $fields = $schema->field_count + $schema->measure_count;
147             my $html = "
148             "; \n"; \n" for @field_names; \n" for @measures; \n";
149            
Cube Report Details
150            
151             my @measures = $schema->measures;
152             my @field_names = $schema->field_names;
153             for(@measures) {
154             $_->[2] = 'count' if $_->[0] eq 'key_count'
155             }
156             @measures = sort {$a->[2] cmp $b->[2]} @measures;
157            
158             header_row: {
159             $html .= "\n
160             $html .= "\t$_
161             $html .= "\t$_->[2]
162             $html .= "
163             }
164            
165             return $html;
166             }
167              
168             sub end_details {
169             my($self,$cube) = @_;
170             my $html = '
';
171             return $html;
172             }
173              
174             sub details_from_table {
175             my($self,$cube,@table) = @_;
176             my $html = "";
177             shift @table;
178             @table = sort { join("\t",@$a) cmp join("\t",@$b)} @table;
179             my $offset = $cube->schema->field_count;
180             for(@table){
181             my $row = $_;
182             $html .= "\n
183             for(my $i = $offset; $i < @$row; ++$i){
184             $row->[$i] = sprintf("%20.2f",$row->[$i]) if $row->[$i] =~ /^-?\d+\.\d*$/
185             }
186             $html .= "\t$_
187             $html .= "\n
188             }
189             return $html;
190             }
191              
192             sub details {
193             my($self,$cube) = @_;
194             my $data = $cube->{cube};
195             my $html = "";
196             my $schema = $cube->schema;
197             my @measures = $schema->measures;
198             my @table = $cube->to_table;
199             return $self->details_from_table($cube,@table);
200             }
201              
202              
203              
204             1;
205              
206              
207              
208              
209              
210              
211             __DATA__