| Image-TextMode documentation | Contained in the Image-TextMode distribution. |
Image::TextMode::Reader - A base class for file readers
This module provides some of the basic functionality for all reader classes.
Creates a new instance.
Reads the contents of $file into $image via the subclass's _read()
method.
Brian Cassidy <bricas@cpan.org>
Copyright 2008-2011 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Image-TextMode documentation | Contained in the Image-TextMode distribution. |
package Image::TextMode::Reader; use Moose; use Carp 'croak';
sub read { ## no critic (Subroutines::ProhibitBuiltinHomonyms) my ( $self, $image, $fh, $options ) = @_; $options ||= {}; $fh = _get_fh( $fh ); $image->sauce->read( $fh ); if ( !$options->{ width } && $image->has_sauce ) { $options->{ width } = $image->sauce->tinfo1; } seek( $fh, 0, 0 ); $self->_read( $image, $fh, $options ); } sub _get_fh { my ( $file ) = @_; my $fh = $file; if ( !ref $fh ) { undef $fh; open $fh, '<', $file ## no critic (InputOutput::RequireBriefOpen) or croak "Unable to open '$file': $!"; } binmode( $fh ); return $fh; } no Moose; __PACKAGE__->meta->make_immutable;
1;