| Image-XBin documentation | Contained in the Image-XBin distribution. |
Image::XBin::Util - Utility functions
use Image::XBin::Util; my $file = create_io_object( %options );
Generates an IO object. Uses IO::File or IO::String.
Copyright 2003-2009 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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;