NAME

Encoding::HandleUtf8 - Fix the encoding for Perl value store (input) and general output (output) to a console or the web.

VERSION

version 0.004

SYNOPSIS

    use Encoding::HandleUtf8 qw( fix_encoding fix_encoding_return );
    
    ########################################################################
    # Simple usage - CAUTION: clones the object.
    
    printf "%s\n", fix_encoding_return 'input', 'Here are some German umlauts: äÄüÜöÖßẞ';
    
    ########################################################################
    # Working with strings.
    
    my $string = 'Here are some German umlauts: äÄüÜöÖßẞ';
    
    # Fix the encoding of a input string to handle them safe within Perl.
    fix_encoding 'input', $string;
    
    # Fix the encoding of a Perl variable for output.
    fix_encoding 'output', $string;
    print "$string\n";
    
    ########################################################################
    # Working with hashes.
    
    my %hash = ( a => 'äÄ', u => 'üÜ', o => 'öÖ', ss => 'ßẞ' );
    
    # Fix the encoding of a hash to handle them safe within Perl.
    fix_encoding 'input', %hash;
    
    # Fix the encoding of a Perl hash for output.
    fix_encoding 'output', %hash;
    print "$_: $hash{$_}\n" for( keys %hash );
    
    ########################################################################
    # Working with hash references.
    
    my $hash = { a => 'äÄ', u => 'üÜ', o => 'öÖ', ss => 'ßẞ' };
    
    # Fix the encoding of a hash reference to handle them safe within Perl.
    fix_encoding 'input', $hash;
    
    # Fix the encoding of a Perl hash reference for output.
    fix_encoding 'output', %hash;
    print "$_: $hash->{$_}\n" for( keys %{ $hash } );
    
    ########################################################################
    # Working with arrays.
    
    my @array = ( 'äÄ', 'üÜ', 'öÖ', 'ßẞ' );
    
    # Fix the encoding of an array to handle them safe within Perl.
    fix_encoding 'input', @array;
    
    # Fix the encoding of a Perl array for output.
    fix_encoding 'output', @array;
    print "$_: $hash{$_}\n" for( @array );
    
    ########################################################################
    # Working with array references.
    
    my $array = [ 'äÄ', 'üÜ', 'öÖ', 'ßẞ' ];
    
    # Fix the encoding of an array reference to handle them safe within Perl.
    fix_encoding 'input', $array;
    
    # Fix the encoding of a Perl array reference for output.
    fix_encoding 'output', @array;
    print "$_: $hash{$_}\n" for( @{ $array } );

DESCRIPTION

Fix the encoding for Perl value store (input) and general output (output) to e.g. a console or the web.

METHODS

fix_encoding

Takes an direction and a object and fixes the encoding.

Required parameters
[0] $direction

The direction in which the object should be fixed. Either input to work safely with inputs (convert to Unicode) or output to output (convert to UTF-8) them to e.g. a console or the web.

[1] $obj

The actual object which should be fixed. Can either be a SCALAR, HASH or ARRAY (including but not mandentory: references).

Optional parameters
[2] $skip_latin

Skips Encoding::FixLatin's fix_latin call on scalars when $skip_latin is set to a true value.

fix_encoding_return

Does and takes exactly the same as "fix_encoding" but instead touching the original supplied object it will clone it an return the new encoded object.

CONFIGURATION

Encoding::HandleUtf8 warns about references it does not know. You can turn off this warnings by adding the reference name to the @IGNORE_LIST array.

    push @Encoding::HandleUtf8::IGNORE_LIST, 'JSON::Boolean';

By default the following references will be ignored (no warnings):

Cpanel::JSON::XS::Boolean
JSON::XS::Boolean
JSON::PP::Boolean
JSON::Boolean

AUTHOR

BURNERSK <burnersk@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2014 by BURNERSK <burnersk@cpan.org>.

This is free software, licensed under:

  The MIT (X11) License