Image::TextMode::Writer - A base class for file writers


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

Index


Code Index:

NAME

Top

Image::TextMode::Writer - A base class for file writers

DESCRIPTION

Top

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

METHODS

Top

new( %args )

Creates a new instance.

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

Writes the contents of $image to $file via the subclass's _write() method.

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


Image-TextMode documentation Contained in the Image-TextMode distribution.
package Image::TextMode::Writer;

use Moose;
use Carp 'croak';

sub write {    ## no critic (Subroutines::ProhibitBuiltinHomonyms)
    my ( $self, $image, $fh, $options ) = @_;
    $options ||= {};
    $fh = _get_fh( $fh );

    $self->_write( $image, $fh, $options );

    $image->sauce->write( $fh ) if $image->has_sauce;
}

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;