Image::XBin::Util - Utility functions


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

Index


Code Index:

NAME

Top

Image::XBin::Util - Utility functions

SYNOPSIS

Top

	use Image::XBin::Util;

	my $file = create_io_object( %options );

METHODS

Top

create_io_object( %options )

Generates an IO object. Uses IO::File or IO::String.

AUTHOR

Top

* Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-XBin documentation Contained in the Image-XBin distribution.
package Image::XBin::Util;

use base qw( Exporter );

use strict;
use warnings;

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

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

sub create_io_object {
	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 ) or croak "$!";
	}
	elsif( exists $options{ string } ) {
		$file = IO::String->new( $options{ string } );
	}
	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;