| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Text::CSV::Encoded::Coder::Encode; | 
| 2 |  |  |  |  |  |  | $Text::CSV::Encoded::Coder::Encode::VERSION = '0.25'; | 
| 3 | 11 |  |  | 11 |  | 203 | use 5.008; | 
|  | 11 |  |  |  |  | 26 |  | 
| 4 | 11 |  |  | 11 |  | 40 | use strict; | 
|  | 11 |  |  |  |  | 13 |  | 
|  | 11 |  |  |  |  | 207 |  | 
| 5 | 11 |  |  | 11 |  | 37 | use warnings; | 
|  | 11 |  |  |  |  | 13 |  | 
|  | 11 |  |  |  |  | 307 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # VERSION | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 11 |  |  | 11 |  | 36 | use base qw( Text::CSV::Encoded::Coder::Base ); | 
|  | 11 |  |  |  |  | 8 |  | 
|  | 11 |  |  |  |  | 4436 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 11 |  |  | 11 |  | 40 | use Carp (); | 
|  | 11 |  |  |  |  | 12 |  | 
|  | 11 |  |  |  |  | 115 |  | 
| 12 | 11 |  |  | 11 |  | 2773 | use Encode (); | 
|  | 11 |  |  |  |  | 40155 |  | 
|  | 11 |  |  |  |  | 3278 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | my %EncoderCache; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub upgrade { | 
| 18 | 9 | 50 |  | 9 | 1 | 30 | utf8::upgrade( $_[1] ) if ( $_[1] ); | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub encode { | 
| 23 | 55 |  |  | 55 | 1 | 184 | my ( $self, $encoding, $str ) = @_; | 
| 24 | 55 | 50 |  |  |  | 84 | return undef unless defined $str; | 
| 25 | 55 |  |  |  |  | 73 | $self->find_encoding( $encoding )->encode( $str, $self->encode_check_value ); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub decode { | 
| 30 | 73 |  |  | 73 | 1 | 73 | my ( $self, $encoding, $str ) = @_; | 
| 31 | 73 | 100 |  |  |  | 109 | return undef unless defined $str; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 72 | 100 | 66 |  |  | 347 | if ( $self->{automatic_UTF8} and $encoding =~ /utf-?8/i ) { | 
| 34 | 46 |  |  |  |  | 126 | return $str; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 26 |  |  |  |  | 37 | $self->find_encoding( $encoding )->decode( $str, $self->decode_check_value ); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub decode_fields_ref { | 
| 42 | 42 |  |  | 42 | 1 | 42 | my ( $self, $encoding, $arrayref ) = @_; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 42 | 100 | 66 |  |  | 166 | if ( $self->{automatic_UTF8} and $encoding =~ /utf-?8/i ) { | 
| 45 | 10 |  |  |  |  | 19 | return; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 32 |  | 50 |  |  | 46 | my $enc = $self->find_encoding( $encoding ) || return; | 
| 49 | 32 |  |  |  |  | 53 | for ( @$arrayref ) { | 
| 50 | 32 | 50 |  |  |  | 89 | $_ = $enc->decode( $_, $self->decode_check_value ) if defined $_; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | sub encode_fields_ref { | 
| 56 | 24 |  |  | 24 | 1 | 25 | my ( $self, $encoding, $arrayref ) = @_; | 
| 57 | 24 |  | 50 |  |  | 29 | my $enc = $self->find_encoding( $encoding ) || return; | 
| 58 | 24 |  |  |  |  | 11333 | for ( @$arrayref ) { | 
| 59 | 24 | 50 |  |  |  | 96 | $_ = $enc->encode( $_, $self->encode_check_value ) if defined $_; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub find_encoding { | 
| 65 | 137 |  |  | 137 | 0 | 105 | shift; | 
| 66 | 137 |  | 50 |  |  | 530 | $EncoderCache { ($_[0] || 'utf8') } | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 66 |  |  |  |  | 
| 67 |  |  |  |  |  |  | ||= Encode::find_encoding( $_[0] || 'utf8' ) || Carp::croak ( "Not found such an encoding name '$_[0]'" ); | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; | 
| 73 |  |  |  |  |  |  | __END__ |