| 1 | package PDF::Table::Settings; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | our $VERSION = '1.007'; # VERSION | |||||||||
| 9 | 4 | our $LAST_UPDATE = '1.003'; # manually update whenever code is changed | |||||||||
| 10 | |||||||||||
| 11 | ########################################################### | ||||||||||
| 12 | # move deprecated settings names to current names, and delete old | ||||||||||
| 13 | # assume any leading '-' already removed | ||||||||||
| 14 | # warning if both deprecated and new name given (use new) | ||||||||||
| 15 | # release at T-6 months, consider issuing warning to remind update needed | ||||||||||
| 16 | # release at T-0 months, give warning on use of deprecated items | ||||||||||
| 17 | # release at T+12 months, remove deprecated names | ||||||||||
| 18 | ############################################################ | ||||||||||
| 19 | |||||||||||
| 20 | 10 | ▶ | sub deprecated_settings { | ||||||||
|
Subroutine
deprecated_settings: called CC=21 SCAR=34.4
Pod
undocumented
| |||||||||||
| 21 | 10 | my ($data, $row_props, $col_props, $cell_props, $header_props, $argref) = @_; | |||||||||
| 22 | # 1 $row_props, 2 $col_props, 3 $cell_props, 4 $header_props | ||||||||||
| 23 | # need to use $_[n] form so that its call be reference, not value | ||||||||||
| 24 | #my $data = $_[0]; | ||||||||||
| 25 | #my $argref = $_[5]; | ||||||||||
| 26 | #my %arg = %{$argref}; | ||||||||||
| 27 | |||||||||||
| 28 | 10 | my %cur_names = ( | |||||||||
| 29 | # old deprecated name new current name | ||||||||||
| 30 | # (old_key) | ||||||||||
| 31 | 'start_y' => 'y', | ||||||||||
| 32 | 'start_h' => 'h', | ||||||||||
| 33 | 'row_height' => 'min_rh', | ||||||||||
| 34 | 'background_color' => 'bg_color', | ||||||||||
| 35 | 'background_color_odd' => 'bg_color_odd', | ||||||||||
| 36 | 'background_color_even' => 'bg_color_even', | ||||||||||
| 37 | 'font_color' => 'fg_color', | ||||||||||
| 38 | 'font_color_odd' => 'fg_color_odd', | ||||||||||
| 39 | 'font_color_even' => 'fg_color_even', | ||||||||||
| 40 | 'font_underline' => 'underline', | ||||||||||
| 41 | #'justify' => 'align', # different set of values allowed | ||||||||||
| 42 | 'lead' => 'leading', | ||||||||||
| 43 | 'border' => 'border_w', | ||||||||||
| 44 | 'horizontal_borders' => 'h_border_w', | ||||||||||
| 45 | 'vertical_borders' => 'v_border_w', | ||||||||||
| 46 | 'border_color' => 'border_c', | ||||||||||
| 47 | # currently same color for H and V borders | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | # global arg | ||||||||||
| 51 | 10 | foreach my $old_key (keys %cur_names) { | |||||||||
| 52 | 150 | ▶ | if (defined $argref->{$old_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | # set deprecated name setting (need to transfer to new name). | ||||||||||
| 54 | # did we also set new name setting? | ||||||||||
| 55 | 14 | ▶ | if (defined $argref->{$cur_names{$old_key}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | carp "!! Warning !! both deprecated global name '$old_key' and current name '$cur_names{$old_key}' given, current name's value used."; | |||||||||
| 57 | } else { | ||||||||||
| 58 | 14 | $argref->{$cur_names{$old_key}} = $argref->{$old_key}; | |||||||||
| 59 | 14 | delete $argref->{$old_key}; | |||||||||
| 60 | # eventually given warning to stop using $old_key | ||||||||||
| 61 | } | ||||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | # row properties | ||||||||||
| 66 | 10 | foreach my $old_key (keys %cur_names) { | |||||||||
| 67 | 150 | ▶ | for (my $row = 0; $row < scalar(@$data); $row++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 285 | ▶ | if (defined $row_props->[$row]->{$old_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | # set deprecated name setting (need to transfer to new name). | ||||||||||
| 70 | 0 | ▶ | if (defined $row_props->[$row]->{$cur_names{$old_key}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | # did we also set new name setting? | ||||||||||
| 72 | 0 | carp "!! Warning !! both deprecated name '$old_key' and current name '$cur_names{$old_key}' given in row_props[$row], current name's value used."; | |||||||||
| 73 | } else { | ||||||||||
| 74 | # transfer deprecated setting to new | ||||||||||
| 75 | 0 | $row_props->[$row]->{$cur_names{$old_key}} = $row_props->[$row]->{$old_key}; | |||||||||
| 76 | 0 | delete $row_props->[$row]->{$old_key}; | |||||||||
| 77 | # eventually given warning to stop using $old_key | ||||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | # column properties | ||||||||||
| 84 | 10 | foreach my $old_key (keys %cur_names) { | |||||||||
| 85 | 150 | ▶ | for (my $col = 0; $col < scalar(@{$col_props}); $col++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 195 | ▶ | if (defined $col_props->[$col]->{$old_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | # set deprecated name setting (need to transfer to new name). | ||||||||||
| 88 | 8 | ▶ | if (defined $col_props->[$col]->{$cur_names{$old_key}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | # did we also set new name setting? | ||||||||||
| 90 | 0 | carp "!! Warning !! both deprecated name '$old_key' and current name '$cur_names{$old_key}' given in column_props[$col], current name's value used."; | |||||||||
| 91 | } else { | ||||||||||
| 92 | # transfer deprecated setting to new | ||||||||||
| 93 | 8 | $col_props->[$col]->{$cur_names{$old_key}} = $col_props->[$col]->{$old_key}; | |||||||||
| 94 | 8 | delete $col_props->[$col]->{$old_key}; | |||||||||
| 95 | # eventually given warning to stop using $old_key | ||||||||||
| 96 | } | ||||||||||
| 97 | } | ||||||||||
| 98 | } | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | # cell properties | ||||||||||
| 102 | 10 | foreach my $old_key (keys %cur_names) { | |||||||||
| 103 | 150 | ▶ | for (my $row = 0; $row < scalar(@$data); $row++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 104 | 285 | ▶ | for ( my $col = 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 1035 | $col < scalar(@{$data->[$row]}); | |||||||||
| 106 | $col++ ) { | ||||||||||
| 107 | 750 | ▶ | if (defined $cell_props->[$row][$col]->{$old_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | # set deprecated name setting (need to transfer to new name). | ||||||||||
| 109 | 2 | ▶ | if (defined $cell_props->[$row][$col]->{$cur_names{$old_key}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | # did we also set new name setting? | ||||||||||
| 111 | 0 | carp "!! Warning !! both deprecated name '$old_key' and current name '$cur_names{$old_key}' given in cell_props[$row][$col], current name's value used."; | |||||||||
| 112 | } else { | ||||||||||
| 113 | # transfer deprecated setting to new | ||||||||||
| 114 | 2 | $cell_props->[$row][$col]->{$cur_names{$old_key}} = $cell_props->[$row][$col]->{$old_key}; | |||||||||
| 115 | 2 | delete $cell_props->[$row][$col]->{$old_key}; | |||||||||
| 116 | # eventually given warning to stop using $old_key | ||||||||||
| 117 | } | ||||||||||
| 118 | } | ||||||||||
| 119 | } | ||||||||||
| 120 | } | ||||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | # header properties | ||||||||||
| 124 | 10 | ▶ | if ($header_props) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | 1 | foreach my $old_key (keys %cur_names) { | |||||||||
| 126 | 15 | ▶ | if (defined $header_props->{$old_key}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 127 | # set deprecated name setting (need to transfer to new name). | ||||||||||
| 128 | # did we also set new name setting? | ||||||||||
| 129 | 0 | ▶ | if (defined $header_props->{$cur_names{$old_key}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | 0 | carp "!! Warning !! both deprecated header name '$old_key' and current name '$cur_names{$old_key}' given, current name's value used."; | |||||||||
| 131 | } else { | ||||||||||
| 132 | 0 | $header_props->{$cur_names{$old_key}} = $header_props->{$old_key}; | |||||||||
| 133 | 0 | delete $header_props->{$old_key}; | |||||||||
| 134 | # eventually given warning to stop using $old_key | ||||||||||
| 135 | } | ||||||||||
| 136 | } | ||||||||||
| 137 | } | ||||||||||
| 138 | } | ||||||||||
| 139 | |||||||||||
| 140 | 10 | return; | |||||||||
| 141 | } # end of deprecated_settings() | ||||||||||
| 142 | |||||||||||
| 143 | ############################################################ | ||||||||||
| 144 | # validate/fix up settings and parameters as much as possible TBD per #12 | ||||||||||
| 145 | ############################################################ | ||||||||||
| 146 | |||||||||||
| 147 | 10 | ▶ | sub check_settings { | ||||||||
|
Subroutine
check_settings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 148 | 10 | my (%arg) = @_; | |||||||||
| 149 | |||||||||||
| 150 | # TBD $arg{} values, some col, row, cell, header? | ||||||||||
| 151 | # x, y >= 0; w, h >= 0; x+w < page width; y+h < page height | ||||||||||
| 152 | # next_h (if def) > 0, next_y (if def) >= 0; next_y+next_h < page height | ||||||||||
| 153 | # line widths >= 0, min_rh > 0 | ||||||||||
| 154 | # TBD in general, validate integer values and possibly some | ||||||||||
| 155 | # other values, per #12 | ||||||||||
| 156 | 10 | return; | |||||||||
| 157 | } # end of check_settings() | ||||||||||
| 158 | |||||||||||
| 159 | 4 | 1; | |||||||||