« Porf/Table/Simple/HtmlReportConfigurator.pm
↑ Summary
Porf/Table/Simple/CsvReportConfigurator.pm »
| 1 | # perl | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Class Report::Porf::Table::Simple::TextReportConfigurator | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Perl Open Report Framework (Porf) | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # Configures a Report::Porf::Table::Simple to write out ASCII- or UTF-Text tables | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # Ralf Peine, Tue May 27 11:29:41 2014 | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # More documentation at the end of file | ||||||||||||||||||||||||||||
| 12 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | $VERSION = "2.001"; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||
| 18 | # Example list with 10 lines (text) | ||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||
| 20 | # *============+======================+=========+=======+======================* | ||||||||||||||||||||||||||||
| 21 | # @ Count @ Prename @ Surname @ Age @ TimeStamp @ | ||||||||||||||||||||||||||||
| 22 | # *------------+----------------------+---------+-------+----------------------* | ||||||||||||||||||||||||||||
| 23 | # | 1 | Vorname 1 | Name 1 | 10 | 0.002329 | | ||||||||||||||||||||||||||||
| 24 | # | 2 | Vorname 2 | Name 2 | 20 | 0.003106 | | ||||||||||||||||||||||||||||
| 25 | # | 3 | Vorname 3 | Name 3 | 30 | 0.003822 | | ||||||||||||||||||||||||||||
| 26 | # | 4 | Vorname 4 | Name 4 | 40 | 0.004533 | | ||||||||||||||||||||||||||||
| 27 | # | 5 | Vorname 5 | Name 5 | 50 | 0.005235 | | ||||||||||||||||||||||||||||
| 28 | # | 6 | Vorname 6 | Name 6 | 60 | 0.005944 | | ||||||||||||||||||||||||||||
| 29 | # | 7 | Vorname 7 | Name 7 | 70 | 0.006656 | | ||||||||||||||||||||||||||||
| 30 | # | 8 | Vorname 8 | Name 8 | 80 | 0.007362 | | ||||||||||||||||||||||||||||
| 31 | # | 9 | Vorname 9 | Name 9 | 90 | 0.008069 | | ||||||||||||||||||||||||||||
| 32 | # | 10 | Vorname 10 | Name 10 | 100 | 0.008779 | | ||||||||||||||||||||||||||||
| 33 | # *============+======================+=========+=======+======================* | ||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||
| 35 | # # Time needed for export of 10 data lines: 0.001954 | ||||||||||||||||||||||||||||
| 36 | # | ||||||||||||||||||||||||||||
| 37 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||
| 44 | # Report::Porf::Table::Simple::TextReportConfigurator; | ||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||
| 46 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | package Report::Porf::Table::Simple::TextReportConfigurator; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | use Report::Porf::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 1 | ▶ | use Report::Porf::Table::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||
| 57 | # Creation / Filling Of Instances | ||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||
| 59 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # --- create Instance ----------------- | ||||||||||||||||||||||||||||
| 62 | sub new | ||||||||||||||||||||||||||||
| 63 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 64 | 10 | my $caller = $_[0]; | |||||||||||||||||||||||||||
| 65 | 10 | ▶ | my $class = ref($caller) || $caller; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $caller || $caller
MC/DC0%0/2
ref $caller || $caller
ref $caller
$caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # let the class go | ||||||||||||||||||||||||||||
| 68 | 10 | my $self = {}; | |||||||||||||||||||||||||||
| 69 | 10 | bless $self, $class; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 10 | return $self; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # --- verbose --------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub set_verbose { | ||||||||||||||||||||||||||
|
Subroutine
set_verbose: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self, # instance_ref | |||||||||||||||||||||||||||
| 78 | $value # value to set | ||||||||||||||||||||||||||||
| 79 | ) = @_; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | $self->{verbose} = $value; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub get_verbose { | ||||||||||||||||||||||||||
|
Subroutine
get_verbose: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, # instance_ref | |||||||||||||||||||||||||||
| 86 | ) = @_; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | return $self->{verbose}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 92 | # | ||||||||||||||||||||||||||||
| 93 | # Configure format | ||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | #-------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # --- create new report and configure ------------------------------------------- | ||||||||||||||||||||||||||||
| 98 | 9 | ▶ | sub create_and_configure_report { | ||||||||||||||||||||||||||
|
Subroutine
create_and_configure_report: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 9 | my ($self # instance_ref | |||||||||||||||||||||||||||
| 100 | ) = @_; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 9 | return $self->configure_report(Report::Porf::Table::Simple->new()); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # --- Configure Export For Text ------------------------------------------------ | ||||||||||||||||||||||||||||
| 106 | 10 | ▶ | sub configure_report { | ||||||||||||||||||||||||||
|
Subroutine
configure_report: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 10 | my ($self, # instance_ref | |||||||||||||||||||||||||||
| 108 | $report2configure, # report to be configured | ||||||||||||||||||||||||||||
| 109 | ) = @_; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 10 | $report2configure->set_format('Text'); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 10 | $report2configure->set_default_column_width (10); | |||||||||||||||||||||||||||
| 114 | 10 | $report2configure->set_default_align ('Left'); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 10 | $report2configure->set_file_start(''); | |||||||||||||||||||||||||||
| 117 | 10 | $report2configure->set_file_end (''); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 10 | $report2configure->set_table_start("\n"); | |||||||||||||||||||||||||||
| 120 | 10 | $report2configure->set_table_end ("\n"); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 10 | $report2configure->set_row_start("|"); | |||||||||||||||||||||||||||
| 123 | 10 | $report2configure->set_row_end ("\n"); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 10 | $report2configure->set_header_row_start("|"); | |||||||||||||||||||||||||||
| 126 | 10 | $report2configure->set_header_row_end ("\n"); | |||||||||||||||||||||||||||
| 127 | 10 | $report2configure->set_header_start(" "); | |||||||||||||||||||||||||||
| 128 | 10 | $report2configure->set_header_end (" |"); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 10 | $report2configure->set_cell_start(" "); | |||||||||||||||||||||||||||
| 131 | 10 | $report2configure->set_cell_end (" |"); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 10 | $report2configure->set_horizontal_separation_start ("*"); | |||||||||||||||||||||||||||
| 134 | 10 | $report2configure->set_horizontal_separation_column_separator ("+"); | |||||||||||||||||||||||||||
| 135 | 10 | $report2configure->set_horizontal_separation_end ("*\n"); | |||||||||||||||||||||||||||
| 136 | 10 | $report2configure->set_horizontal_separation_char ("-"); | |||||||||||||||||||||||||||
| 137 | 10 | $report2configure->set_horizontal_separation_bold_char ("="); | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | #=================================================================================== | ||||||||||||||||||||||||||||
| 140 | # | ||||||||||||||||||||||||||||
| 141 | # Configure Actions, no need to speed up | ||||||||||||||||||||||||||||
| 142 | # | ||||||||||||||||||||||||||||
| 143 | #=================================================================================== | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # === Column store Action ============================================================ | ||||||||||||||||||||||||||||
| 146 | $report2configure->set_configure_column_action( | ||||||||||||||||||||||||||||
| 147 | 52 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=22 SCAR=34.2
| |||||||||||||||||||||||||||||
| 148 | 52 | my $report = shift; # instance_ref | |||||||||||||||||||||||||||
| 149 | 52 | my %options = @_; # options | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 52 | ▶ | print_hash_ref(\%options) if verbose($report, 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 52 | my $cell_start = $report->get_cell_start(); | |||||||||||||||||||||||||||
| 154 | 52 | my $cell_end = $report->get_cell_end(); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 52 | my $left = ""; # left from value | |||||||||||||||||||||||||||
| 157 | 52 | my $right = ""; # right from value | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # --- default value --------------------------------------- | ||||||||||||||||||||||||||||
| 160 | 52 | my $default_value = get_option_value(\%options, qw (-default_value -def_val -dv)); | |||||||||||||||||||||||||||
| 161 | 52 | ▶ | $default_value = $report->get_default_cell_value() unless defined $default_value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # --- value --------------------------------------- | ||||||||||||||||||||||||||||
| 164 | 52 | my $value = interprete_value_options(\%options); | |||||||||||||||||||||||||||
| 165 | 52 | my $value_ref = ref($value); | |||||||||||||||||||||||||||
| 166 | 52 | my $value_action; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 52 | ▶ | die "value action not defined" unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 52 | ▶ | if ($value_ref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if ($value_ref =~ /^CODE/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 2 | $value_action = $value; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||||||||||
| 175 | # or what ?? | ||||||||||||||||||||||||||||
| 176 | 0 | die "# ref(value_ref) = $value_ref unknown"; | |||||||||||||||||||||||||||
| 177 | # $value_action = eval ("sub { return $$value; };"); | ||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||
| 181 | 50 | $value = complete_value_code($value, $default_value); | |||||||||||||||||||||||||||
| 182 | 50 | $value_action = $report->create_action("$value;"); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # --- format value ---------------------------------------- | ||||||||||||||||||||||||||||
| 186 | 52 | my $format = get_option_value(\%options, qw (-format -f)); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 52 | ▶ | if ($format) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | my $format_ref = ref($format); | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | die "You used a '$format_ref' type to set the 'Format', " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | ."but currently only strings are supported!" | ||||||||||||||||||||||||||||
| 193 | if $format_ref; | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | print "format $format\n" if verbose($report, 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | $left = "sprintf(\"$format\", ".$left; | |||||||||||||||||||||||||||
| 198 | 0 | $right .= ")"; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # --- coloring is not supported for text ------------------ | ||||||||||||||||||||||||||||
| 202 | 52 | my $color = get_option_value(\%options, qw (-color -c)); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 52 | ▶ | print "color cannot be supported for text (color = $color)\n" if verbose($report, 3) && $color; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
verbose($report, 3) and $color
MC/DC0%0/2
verbose($report, 3) and $color
verbose($report, 3)
$color
Truth table33%1/3
A and B
A= verbose($report, 3)B= $color
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # --- width / align --------------------------------------- | ||||||||||||||||||||||||||||
| 207 | 52 | my $width = get_option_value(\%options, qw (-width -w)); | |||||||||||||||||||||||||||
| 208 | 52 | my $align = get_option_value(\%options, qw (-align -a)); | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 52 | ▶ | $width = $report->get_default_column_width() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | unless defined $width; | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 52 | ▶ | if ($align) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 50 | my $align_ref = ref($align); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 50 | ▶ | die "You used a '$align_ref' type to set the 'Align', " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | ."but currently only strings are supported!" | ||||||||||||||||||||||||||||
| 218 | if $align_ref; | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 50 | $align = interprete_alignment($align); | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 50 | ▶ | print "align $align\n" if verbose($report, 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | else { | ||||||||||||||||||||||||||||
| 225 | 2 | $align = ''; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 52 | ▶ | if (defined $width) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 52 | my $width_ref = ref($width); | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 52 | ▶ | die "You used a '$width_ref' type to set the 'Width', " | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | ."but currently only strings are supported!" | ||||||||||||||||||||||||||||
| 233 | if $width_ref; | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 52 | ▶ | print "width $width\n" if verbose($report, 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 52 | push (@{$report->get_column_widths_ref()}, $width); | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 52 | ▶ | $align = "left" unless $align; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | 52 | $align = lc($align); | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 52 | $left = "const_length_$align($width, ".$left; | |||||||||||||||||||||||||||
| 243 | 52 | $right .= ")"; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # --- configure header ---------------------------- | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 52 | my $header_text = get_option_value(\%options, qw (-header -h)); | |||||||||||||||||||||||||||
| 249 | 52 | ▶ | $header_text = '' unless defined $header_text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 52 | push (@{$report->get_header_texts_ref()}, $header_text); | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | # --- --------------------------------------------- | ||||||||||||||||||||||||||||
| 253 | # --- --------------------------------------------- | ||||||||||||||||||||||||||||
| 254 | # --- --------------------------------------------- | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # --- build cell content action --------------------------------------------- | ||||||||||||||||||||||||||||
| 257 | 52 | my $cell_action_str = $left.'$value_action->($_[0])'.$right; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 52 | my $eval_str = 'sub { return $cell_start.'.$cell_action_str.'.$cell_end; }'; | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 52 | ▶ | print "### eval_str = sub { return $cell_start$cell_action_str$cell_end; }\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | if verbose($report, 3); | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 52 | my $cell_action = eval ($eval_str); | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 52 | ▶ | print "### ref(cell_action) ".ref($cell_action) ."\n" if verbose($report, 3); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 52 | $report->add_cell_output_action($cell_action); | |||||||||||||||||||||||||||
| 269 | 10 | }); | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | # === Configure Complete Action ==================================================== | ||||||||||||||||||||||||||||
| 272 | $report2configure->set_configure_complete_action( | ||||||||||||||||||||||||||||
| 273 | 10 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 274 | 10 | my ($report, # instance_ref | |||||||||||||||||||||||||||
| 275 | ) = @_; | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | # --- Build Header Lines ------------------------------------------- | ||||||||||||||||||||||||||||
| 278 | 10 | my $start_col = ''; | |||||||||||||||||||||||||||
| 279 | 10 | my $start_col_bold = ''; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 10 | my $additional_sep_start_chars = ''; | |||||||||||||||||||||||||||
| 282 | 10 | my $additional_sep_end_chars = ''; | |||||||||||||||||||||||||||
| 283 | 10 | my $additional_bold_sep_start_chars = ''; | |||||||||||||||||||||||||||
| 284 | 10 | my $additional_bold_sep_end_chars = ''; | |||||||||||||||||||||||||||
| 285 | 10 | my $columSeparatorLength = length($report->get_horizontal_separation_column_separator()); | |||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 10 | my $cell_start_length = length($report->get_cell_start()); | |||||||||||||||||||||||||||
| 288 | 10 | my $cell_end_length = length($report->get_cell_end()) - $columSeparatorLength; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 10 | my $bold_cell_start_length = length($report->get_header_start()); | |||||||||||||||||||||||||||
| 291 | 10 | my $bold_cell_end_length = length($report->get_header_end()) - $columSeparatorLength; | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # print "$cell_start_length, $cell_end_length\n"; | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 10 | ▶ | $additional_sep_start_chars = $report->get_horizontal_separation_char() x $cell_start_length | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | if $cell_start_length > 0; | ||||||||||||||||||||||||||||
| 297 | 10 | ▶ | $additional_sep_end_chars = $report->get_horizontal_separation_char() x $cell_end_length | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | if $cell_end_length > 0; | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 10 | ▶ | $additional_bold_sep_start_chars = $report->get_horizontal_separation_bold_char() x $bold_cell_start_length | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | if $bold_cell_start_length > 0; | ||||||||||||||||||||||||||||
| 302 | 10 | ▶ | $additional_bold_sep_end_chars = $report->get_horizontal_separation_bold_char() x $bold_cell_end_length | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | if $bold_cell_end_length > 0; | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 10 | my $sep = $report->get_horizontal_separation_start() | |||||||||||||||||||||||||||
| 306 | .$additional_sep_start_chars; | ||||||||||||||||||||||||||||
| 307 | 10 | my $sep_bold = $report->get_horizontal_separation_start() | |||||||||||||||||||||||||||
| 308 | .$additional_bold_sep_start_chars; | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # --- build separator lines --- | ||||||||||||||||||||||||||||
| 311 | 10 | foreach my $width (@{$report->get_column_widths_ref()}) { | |||||||||||||||||||||||||||
| 312 | 52 | $sep .= $start_col. | |||||||||||||||||||||||||||
| 313 | $report->get_horizontal_separation_char() x $width; | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 52 | $sep_bold .= $start_col_bold. | |||||||||||||||||||||||||||
| 316 | $report->get_horizontal_separation_bold_char() x $width; | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 52 | $start_col_bold = | |||||||||||||||||||||||||||
| 319 | $additional_bold_sep_start_chars x $columSeparatorLength | ||||||||||||||||||||||||||||
| 320 | .$report->get_horizontal_separation_column_separator() | ||||||||||||||||||||||||||||
| 321 | .$additional_bold_sep_end_chars; | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 52 | $start_col = | |||||||||||||||||||||||||||
| 324 | $additional_sep_start_chars x $columSeparatorLength | ||||||||||||||||||||||||||||
| 325 | .$report->get_horizontal_separation_column_separator() | ||||||||||||||||||||||||||||
| 326 | .$additional_sep_end_chars; | ||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 10 | $sep .= $report->get_horizontal_separation_char() | |||||||||||||||||||||||||||
| 330 | .$report->get_horizontal_separation_end(); | ||||||||||||||||||||||||||||
| 331 | 10 | $sep_bold .= $report->get_horizontal_separation_bold_char() | |||||||||||||||||||||||||||
| 332 | .$report->get_horizontal_separation_end(); | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 10 | $report->set_header_line ($sep); | |||||||||||||||||||||||||||
| 335 | 10 | $report->set_separator_line ($sep); | |||||||||||||||||||||||||||
| 336 | 10 | $report->set_bold_header_line($sep_bold); | |||||||||||||||||||||||||||
| 337 | 10 | $report->set_table_end ($sep_bold); | |||||||||||||||||||||||||||
| 338 | 10 | }); | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | #=================================================================================== | ||||||||||||||||||||||||||||
| 341 | # | ||||||||||||||||||||||||||||
| 342 | # Runtime Actions, no need to speed up | ||||||||||||||||||||||||||||
| 343 | # | ||||||||||||||||||||||||||||
| 344 | #=================================================================================== | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # === Header Output Action ============================================================ | ||||||||||||||||||||||||||||
| 347 | $report2configure->set_header_output_action( | ||||||||||||||||||||||||||||
| 348 | 8 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 349 | 8 | my ($report, # instance_ref | |||||||||||||||||||||||||||
| 350 | $data_ref # data to output | ||||||||||||||||||||||||||||
| 351 | ) = @_; | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 8 | my $header_string = $report->get_header_row_start(); | |||||||||||||||||||||||||||
| 354 | 8 | my $c = 0; | |||||||||||||||||||||||||||
| 355 | 8 | foreach my $header_text (@{$data_ref}) { | |||||||||||||||||||||||||||
| 356 | 42 | $header_string .= $report->get_header_start() | |||||||||||||||||||||||||||
| 357 | .const_length_center($report->get_column_widths_ref()->[$c], | ||||||||||||||||||||||||||||
| 358 | $header_text) | ||||||||||||||||||||||||||||
| 359 | .$report->get_header_end(); | ||||||||||||||||||||||||||||
| 360 | 42 | $c++; | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 8 | $header_string .= $report->get_header_row_end(); | |||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 8 | ▶ | print "### Header String:$header_string" if verbose($report, 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 8 | return $header_string; | |||||||||||||||||||||||||||
| 368 | 10 | }); | |||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | # === Start Table Output Action ============================================================ | ||||||||||||||||||||||||||||
| 371 | $report2configure->set_start_table_output_action( | ||||||||||||||||||||||||||||
| 372 | 8 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 373 | 8 | my ($report, # instance_ref | |||||||||||||||||||||||||||
| 374 | $data_ref # data to output | ||||||||||||||||||||||||||||
| 375 | ) = @_; | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 8 | return $report->get_file_start() | |||||||||||||||||||||||||||
| 378 | .$report->get_table_start() | ||||||||||||||||||||||||||||
| 379 | .$report->get_bold_header_line() | ||||||||||||||||||||||||||||
| 380 | .$report->get_header_output() | ||||||||||||||||||||||||||||
| 381 | .$report->get_header_line(); | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 10 | }); | |||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | # === End Table Output Action ============================================================ | ||||||||||||||||||||||||||||
| 386 | $report2configure->set_end_table_output_action( | ||||||||||||||||||||||||||||
| 387 | 8 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 388 | 8 | my ($report, # instance_ref | |||||||||||||||||||||||||||
| 389 | $data_ref # data to output | ||||||||||||||||||||||||||||
| 390 | ) = @_; | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 8 | return $report->get_table_end() | |||||||||||||||||||||||||||
| 393 | .$report->get_file_end(); | ||||||||||||||||||||||||||||
| 394 | 10 | }); | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | #=================================================================================== | ||||||||||||||||||||||||||||
| 397 | # | ||||||||||||||||||||||||||||
| 398 | # Runtime Mass Data Actions, be careful, don't slow it down !! | ||||||||||||||||||||||||||||
| 399 | # | ||||||||||||||||||||||||||||
| 400 | #=================================================================================== | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 10 | my $previous_data_ref = ''; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | # === Row Output Action ============================================================ | ||||||||||||||||||||||||||||
| 405 | $report2configure->set_row_output_action( | ||||||||||||||||||||||||||||
| 406 | 53 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 407 | 53 | my ($report, # instance_ref | |||||||||||||||||||||||||||
| 408 | $data_ref # data to output | ||||||||||||||||||||||||||||
| 409 | ) = @_; | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 53 | my $cell_output_actions_ref = $report->get_cell_output_actions(); | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 53 | my $row_string = ''; | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | # --- Add something when group changes ---- | ||||||||||||||||||||||||||||
| 416 | 53 | my $row_group_changes_action = $report->get_row_group_changes_action(); | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 53 | ▶ | $row_string .= $row_group_changes_action->($previous_data_ref, $data_ref) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 419 | if $row_group_changes_action; | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | 53 | $previous_data_ref = $data_ref; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | # --- start new row ----------------------- | ||||||||||||||||||||||||||||
| 424 | 53 | $row_string .= $report->get_row_start(); | |||||||||||||||||||||||||||
| 425 | 53 | foreach my $action (@$cell_output_actions_ref) { | |||||||||||||||||||||||||||
| 426 | 290 | ▶ | print "### action $action\n" if verbose($report, 4); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 290 | $row_string .= $action->($data_ref); | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 53 | $row_string .= $report->get_row_end(); | |||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 53 | ▶ | print "### Row String:$row_string" if verbose($report, 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | 53 | return $row_string; | |||||||||||||||||||||||||||
| 435 | 10 | }); | |||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 10 | return $report2configure; | |||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||
| 439 | 1 | 1; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head1 NAME | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | C<Report::Porf::Table::Simple::TextReportConfigurator> | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | Configures a Report::Porf::Table::Simple to write out ASCII- or UTF-Text tables. | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | Part of Perl Open Report Framework (Porf). | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | =head1 Documentation | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | See Report::Porf::Framework.pm for documentation of features and usage. | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | Copyright (c) 2013 by Ralf Peine, Germany. All rights reserved. | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 458 | it under the same terms as Perl itself, either Perl version 5.6.0 or, | ||||||||||||||||||||||||||||
| 459 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | =head1 DISCLAIMER OF WARRANTY | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | This library is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 464 | but without any warranty; without even the implied warranty of | ||||||||||||||||||||||||||||
| 465 | merchantability or fitness for a particular purpose. | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | =cut | ||||||||||||||||||||||||||||