Image::TextMode::Format - A base class for text mode file formats


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

Index


Code Index:

NAME

Top

Image::TextMode::Format - A base class for text mode file formats

DESCRIPTION

Top

This is a base class for all textmode formats. It provides the basic structure for reading and writing, plus provides some defaults for common attributes (e.g. font and palette).

ACCESSORS

Top

* reader - an instance of a file reader
* writer - and instance of a file writer
* font - a font instance
* palette - a palette instance
* sauce - a SAUCE metadata object
* render_options - default options for use when rasterizing the data

METHODS

Top

new( %args )

Creates a new instance.

read( $file, \%options )

Proxies to the reader's read() method.

write( $file, \%options )

Proxies to the writer's write() method.

PROXIED METHODS

Top

The following methods are proxies to sauce.

* author
* title
* group
* has_sauce

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top


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

use Moose;

require Class::MOP;
use Image::TextMode::Font::8x16;
use Image::TextMode::Palette::VGA;
use Image::TextMode::SAUCE;

has 'reader' => (
    is         => 'ro',
    isa        => 'Image::TextMode::Reader',
    lazy_build => 1,
);

has 'writer' => (
    is         => 'ro',
    isa        => 'Image::TextMode::Writer',
    lazy_build => 1,
);

sub _build_reader {
    my ( $self ) = @_;
    return $self->_xs_or_not( 'Reader' );
}

sub _build_writer {
    my ( $self ) = @_;
    return $self->_xs_or_not( 'Writer' );
}

sub _xs_or_not {
    my ( $class, $type ) = @_;
    ( my $name = ( ref $class || $class ) ) =~ s{\bFormat\b}{$type}s;

    unless ( $ENV{ IMAGE_TEXTMODE_NOXS } ) {
        my $xs = $name . '::XS';
        my $result = eval { Class::MOP::load_class( $xs ); };
        if ( $result && !$@ ) { return $xs->new; }
    }

    Class::MOP::load_class( $name );
    return $name->new;
}

has 'font' => (
    is      => 'rw',
    isa     => 'Object',
    default => sub { Image::TextMode::Font::8x16->new }
);

has 'palette' => (
    is      => 'rw',
    isa     => 'Object',
    default => sub { Image::TextMode::Palette::VGA->new }
);

has 'sauce' => (
    is      => 'rw',
    isa     => 'Object',
    default => sub { Image::TextMode::SAUCE->new },
    handles => [ qw( author title group has_sauce ) ]
);

has 'render_options' =>
    ( is => 'rw', isa => 'HashRef', default => sub { {} } );

sub read {    ## no critic (Subroutines::ProhibitBuiltinHomonyms)
    my ( $self, @rest ) = @_;
    $self->reader->read( $self, @rest );
}

sub write {    ## no critic (Subroutines::ProhibitBuiltinHomonyms)
    my ( $self, @rest ) = @_;
    $self->writer->write( $self, @rest );
}

no Moose;

__PACKAGE__->meta->make_immutable;

1;