Image::ANSI::Utils - Utility funtions


Image-ANSI documentation Contained in the Image-ANSI distribution.

Index


Code Index:

NAME

Top

Image::ANSI::Utils - Utility funtions

SYNOPSIS

Top

	use Image::ANSI::Utils

	my $file = create_io_object( file => $file );

METHODS

Top

create_io_object( %options, $perms )

Creates an IO::File object or IO::String object.

	# for reading...
	$file = create_io_object( file => $file, '<' );
	$file = create_io_object( handle => $handle, '<' );
	$file = create_io_object( string => \$string, '<' );

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-ANSI documentation Contained in the Image-ANSI distribution.
package Image::ANSI::Utils;

use strict;
use warnings;

use base qw( Exporter );

our @EXPORT  = qw( create_io_object );
our $VERSION = '0.10';

use IO::File;
use IO::String;
use Carp;

sub create_io_object {
	my $self    = shift;
	my %options = %{ $_[ 0 ] };
	my $perms   = $_[ 1 ];

	my $file;

	# use appropriate IO object for what we get in
	if( exists $options{ file } ) {
		$file = IO::File->new( $options{ file }, $perms ) || croak "$!";
	}
	elsif( exists $options{ string } ) {
		$file = IO::String->new( $options{ string }, $perms );
	}
	elsif( exists $options{ handle } ) {
		$file = $options{ handle };
	}
	else {
		croak( "No valid read type. Must be one of 'file', 'string' or 'handle'." );
	}

	binmode( $file );
	return $file;
}

1;