NAME

Krang::IO - abstract away any IO operations that need to be Charset-aware


SYNOPSIS

    my $FH;
    # for writing
    pkg('IO')->open($FH, '>', '/some/file')
        or die "Could not open for writing: $!";
    # for reading
    pkg('IO')->open($FH, '<', '/some/file')
        or die "Could not open for reading: $!";
    # get an IO::File object with the right encoding
    my $io = pkg('IO')->io_file(">/some/file");
    # print to STDOUT with the correct encoding
    pkg('IO')->print($some_string);
    # print to STDOUT with a trailing newline with the correct encoding
    pkg('IO')->say($some_string);
    # print to STDERR with a trailing newline with the correct encoding
    pkg('IO')->warn($some_string);


DESCRIPTION

Krang can be setup to run on multiple character sets. A lot of the common character sets don't need anything really special to interact with the files but some (like UTF-8) do.

This module provides the necessary abstraction so that for the most part you don't need to worry about that.


INTERFACE

open

This works like Perl's built-in open (the 3 argument version), but will set the appropriate encoding based on the Charset.

    my $FH;
    # for writing
    pkg('IO')->open($FH, '>', '/some/file')
        or die "Could not open for writing: $!";

io_file

This returns a new IO::File object and acts just like single arg form of IO::File::new().

To read/write a file in binary mode (by-passing the Charset directive) pass the optional 'binary' argument in.

    my $io = pkg('IO')->io_file(">/some/file");
    my $io = pkg('IO')->io_file(">/some/file", 'binary' => 1);

print

Prints a message to STDOUT (or the default select()ed file handle) with the correct character set encoding.

say

Prints a message to STDOUT (or the default select()ed file handle) with a trailing newline added, with the correct character set encoding.

warn

Prints a message to STDERR with a trailing newline added.