Image::TextMode::Reader - A base class for file readers


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

Index


Code Index:

NAME

Top

Image::TextMode::Reader - A base class for file readers

DESCRIPTION

Top

This module provides some of the basic functionality for all reader classes.

METHODS

Top

new( %args )

Creates a new instance.

read( $image, $file, \%options )

Reads the contents of $file into $image via the subclass's _read() method.

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


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;