| Image-TextMode documentation | Contained in the Image-TextMode distribution. |
Image::TextMode::Format - A base class for text mode file formats
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).
Creates a new instance.
Proxies to the reader's read() method.
Proxies to the writer's write() method.
The following methods are proxies to sauce.
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::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;