| 1 | package Spreadsheet::Reader::Format::FmtDefault; | ||||||||||||||||||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:JANDREW'; | |||||||||||||||||||||||||||
| 3 | 3 | ▶ | use version; our $VERSION = version->declare('v0.6.4'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | #~ use Log::Shiras::Unhide qw( :debug ); | ||||||||||||||||||||||||||||
| 5 | ###LogSD warn "You uncovered internal logging statements for Spreadsheet::Reader::Format::FmtDefault-$VERSION"; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Types::Standard qw( HashRef Str is_ArrayRef is_HashRef is_StrictNum );# | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | ###LogSD use Log::Shiras::Telephone; | ||||||||||||||||||||||||||||
| 13 | ###LogSD with 'Log::Shiras::LogSpace'; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #########1 Dispatch Tables 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #########1 Public Attributes 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | has excel_region =>( | |||||||||||||||||||||||||||
| 22 | isa => Str, | ||||||||||||||||||||||||||||
| 23 | default => 'en', | ||||||||||||||||||||||||||||
| 24 | reader => 'get_excel_region', | ||||||||||||||||||||||||||||
| 25 | writer => 'set_excel_region', | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | has target_encoding =>( | |||||||||||||||||||||||||||
| 29 | isa => Str, | ||||||||||||||||||||||||||||
| 30 | reader => 'get_target_encoding', | ||||||||||||||||||||||||||||
| 31 | writer => 'set_target_encoding', | ||||||||||||||||||||||||||||
| 32 | predicate => 'has_target_encoding', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | has defined_excel_translations =>( | ||||||||||||||||||||||||||||
| 36 | isa => HashRef, | ||||||||||||||||||||||||||||
| 37 | traits => ['Hash'], | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | default => sub{ { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 3 | 0x00 => 'General', | |||||||||||||||||||||||||||
| 40 | 0x01 => '0', | ||||||||||||||||||||||||||||
| 41 | 0x02 => '0.00', | ||||||||||||||||||||||||||||
| 42 | 0x03 => '#,##0', | ||||||||||||||||||||||||||||
| 43 | 0x04 => '#,##0.00', | ||||||||||||||||||||||||||||
| 44 | 0x05 => '$#,##0_);($#,##0)', | ||||||||||||||||||||||||||||
| 45 | 0x06 => '$#,##0_);[Red]($#,##0)', | ||||||||||||||||||||||||||||
| 46 | 0x07 => '$#,##0.00_);($#,##0.00)', | ||||||||||||||||||||||||||||
| 47 | 0x08 => '$#,##0.00_);[Red]($#,##0.00)', | ||||||||||||||||||||||||||||
| 48 | 0x09 => '0%', | ||||||||||||||||||||||||||||
| 49 | 0x0A => '0.00%', | ||||||||||||||||||||||||||||
| 50 | 0x0B => '0.00E+00', | ||||||||||||||||||||||||||||
| 51 | 0x0C => '# ?/?', | ||||||||||||||||||||||||||||
| 52 | 0x0D => '# ??/??', | ||||||||||||||||||||||||||||
| 53 | 0x0E => 'yyyy-mm-dd', # Was 'm-d-yy', which is bad as system default | ||||||||||||||||||||||||||||
| 54 | 0x0F => 'd-mmm-yy', | ||||||||||||||||||||||||||||
| 55 | 0x10 => 'd-mmm', | ||||||||||||||||||||||||||||
| 56 | 0x11 => 'mmm-yy', | ||||||||||||||||||||||||||||
| 57 | 0x12 => 'h:mm AM/PM', | ||||||||||||||||||||||||||||
| 58 | 0x13 => 'h:mm:ss AM/PM', | ||||||||||||||||||||||||||||
| 59 | 0x14 => 'h:mm', | ||||||||||||||||||||||||||||
| 60 | 0x15 => 'h:mm:ss', | ||||||||||||||||||||||||||||
| 61 | 0x16 => 'm-d-yy h:mm', | ||||||||||||||||||||||||||||
| 62 | 0x1F => '#,##0_);(#,##0)', | ||||||||||||||||||||||||||||
| 63 | 0x20 => '#,##0_);[Red](#,##0)', | ||||||||||||||||||||||||||||
| 64 | 0x21 => '#,##0.00_);(#,##0.00)', | ||||||||||||||||||||||||||||
| 65 | 0x22 => '#,##0.00_);[Red](#,##0.00)', | ||||||||||||||||||||||||||||
| 66 | 0x23 => '_(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)', | ||||||||||||||||||||||||||||
| 67 | 0x24 => '_($*#,##0_);_($*(#,##0);_($*"-"_);_(@_)', | ||||||||||||||||||||||||||||
| 68 | 0x25 => '_(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)', | ||||||||||||||||||||||||||||
| 69 | 0x26 => '_($*#,##0.00_);_($*(#,##0.00);_($*"-"??_);_(@_)', | ||||||||||||||||||||||||||||
| 70 | 0x27 => 'mm:ss', | ||||||||||||||||||||||||||||
| 71 | 0x28 => '[h]:mm:ss', | ||||||||||||||||||||||||||||
| 72 | 0x29 => 'mm:ss.0', | ||||||||||||||||||||||||||||
| 73 | 0x2A => '##0.0E+0', | ||||||||||||||||||||||||||||
| 74 | 0x2B => '@', | ||||||||||||||||||||||||||||
| 75 | 0x31 => '@', | ||||||||||||||||||||||||||||
| 76 | } }, | ||||||||||||||||||||||||||||
| 77 | 3 | handles =>{ | |||||||||||||||||||||||||||
| 78 | _get_defined_excel_format => 'get', | ||||||||||||||||||||||||||||
| 79 | _set_defined_excel_format => 'set', | ||||||||||||||||||||||||||||
| 80 | total_defined_excel_formats => 'count', | ||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | #########1 Public Methods 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 187 | ▶ | sub get_defined_excel_format{ | ||||||||||||||||||||||||||
|
Subroutine
get_defined_excel_format: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 187 | my ( $self, $position, ) = @_; | |||||||||||||||||||||||||||
| 88 | ###LogSD my $phone = Log::Shiras::Telephone->new( name_space => | ||||||||||||||||||||||||||||
| 89 | ###LogSD $self->get_all_space . '::get_defined_excel_format', ); | ||||||||||||||||||||||||||||
| 90 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 91 | ###LogSD "Getting the defined excel format for position: $position", ] ); | ||||||||||||||||||||||||||||
| 92 | 187 | ▶ | my $int_value = ( $position =~ /0x/ ) ? hex( $position ) : $position; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 94 | ###LogSD "..after int conversion: $int_value", ] ); | ||||||||||||||||||||||||||||
| 95 | 187 | return $self->_get_defined_excel_format( $int_value ); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | sub set_defined_excel_formats{ | ||||||||||||||||||||||||||
|
Subroutine
set_defined_excel_formats: called CC=10 SCAR=24.5
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 2 | my ( $self, @args, ) = @_; | |||||||||||||||||||||||||||
| 100 | ###LogSD my $phone = Log::Shiras::Telephone->new( name_space => | ||||||||||||||||||||||||||||
| 101 | ###LogSD $self->get_all_space . '::set_defined_excel_format', ); | ||||||||||||||||||||||||||||
| 102 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 103 | ###LogSD "Setting defined excel formats" ] ); | ||||||||||||||||||||||||||||
| 104 | ###LogSD $phone->talk( level => 'trace', message => [ | ||||||||||||||||||||||||||||
| 105 | ###LogSD "..from the list: ", @args, ] ); | ||||||||||||||||||||||||||||
| 106 | 2 | my $position_ref; | |||||||||||||||||||||||||||
| 107 | 2 | ▶ | if( @args > 1 and @args % 2 == 0 ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args > 1 and @args % 2 == 0
MC/DC0%0/2
@args > 1 and @args % 2 == 0
@args > 1
@args % 2 == 0
Truth table33%1/3
A and B
A= @args > 1B= @args % 2 == 0
| |||||||||||||||||||||||||||||
| 108 | 0 | $position_ref = { @args }; | |||||||||||||||||||||||||||
| 109 | }else{ | ||||||||||||||||||||||||||||
| 110 | 2 | $position_ref = $args[0]; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 2 | ▶ | if( is_ArrayRef( $position_ref ) ){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 113 | 1 | my $x = -1; | |||||||||||||||||||||||||||
| 114 | 1 | for my $format_string ( @$position_ref ){ | |||||||||||||||||||||||||||
| 115 | 24 | $x++; | |||||||||||||||||||||||||||
| 116 | 24 | ▶ | next if !defined $format_string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 118 | ###LogSD "Setting position -$x- to format string: $format_string", ] ); | ||||||||||||||||||||||||||||
| 119 | 1 | $self->_set_defined_excel_format( $x => $format_string ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | }elsif( is_HashRef( $position_ref ) ){ | ||||||||||||||||||||||||||||
| 122 | 1 | for my $key ( keys %$position_ref ){ | |||||||||||||||||||||||||||
| 123 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 124 | ###LogSD "Setting the defined excel format for position -$key- to : ", $position_ref->{$key}, ] ); | ||||||||||||||||||||||||||||
| 125 | 1 | ▶ | my $int_value = ( $key =~ /0x/ ) ? hex( $key ) : $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | confess "The key -$key- must translate to a number!" if !is_StrictNum( $int_value ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 128 | ###LogSD "Initial -$key- translated to position: " . $int_value, ] ); | ||||||||||||||||||||||||||||
| 129 | 1 | $self->_set_defined_excel_format( $int_value => $position_ref->{$key} ); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | }else{ | ||||||||||||||||||||||||||||
| 132 | 0 | confess "Unrecognized format passed: " . join( '~|~', @$position_ref ); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 2 | return 1; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | sub change_output_encoding{ | ||||||||||||||||||||||||||
|
Subroutine
change_output_encoding: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 2 | my ( $self, $string, ) = @_; | |||||||||||||||||||||||||||
| 139 | 2 | ▶ | return undef if !defined $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | ###LogSD my $phone = Log::Shiras::Telephone->new( name_space => | ||||||||||||||||||||||||||||
| 141 | ###LogSD $self->get_all_space . '::change_output_encoding', ); | ||||||||||||||||||||||||||||
| 142 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 143 | ###LogSD "Changing the encoding of: $string", | ||||||||||||||||||||||||||||
| 144 | ###LogSD ($self->has_target_encoding ? ('..to encoding type: ' . $self->get_target_encoding) : ''), ] ); | ||||||||||||||||||||||||||||
| 145 | 2 | ▶ | my $output = $self->has_target_encoding ? decode( $self->get_target_encoding, $string ) : $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | ###LogSD $phone->talk( level => 'info', message => [ | ||||||||||||||||||||||||||||
| 147 | ###LogSD "Final output: $output", ] ); | ||||||||||||||||||||||||||||
| 148 | 2 | return $output; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | #########1 Private Attributes 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | #########1 Private Methods 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | #########1 Phinish 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 3 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 162 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 3 | 1; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | #########1 Documentation 3#########4#########5#########6#########7#########8#########9 | ||||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||