Leon Brocard wrote:

> It's hard to tell without showing us docs

  <http://search.cpan.org/~summer/Image-Xbm-1.08/Xbm.pm>

and s/xbm/pbm/g ;-)

> and code.

  use Image::Xbm(); our @ISA = 'Image::Xbm';
  use Image::PBMlib();

  sub load
  {
    my $self = shift ;
    my $file = shift || $self->get(-file ) or die 'No file specified';

    open my $fh, $file or die "Failed to open `$file': $!";

    my $h = Image::PBMlib::readppmheader( $fh );
    die "Failed to parse header in `$file': $h->{error}" if $h->{error};
    die "Wrong magic number: ($h->{type})" if $h->{type} != 1;

    $self->_set(  -file => $file );
    $self->_set( -width => $h->{width} );
    $self->_set(-height => $h->{height} );
    $self->_set(  -bits => pack 'b*', join '', Image::PBMlib::readpixels_dec(
      $fh, $h->{type}, $h->{width} * $h->{height} ) );
  }

  sub save
  {
    my $self = shift;
    my $file = shift || $self->get(-file ) or die 'No file specified';

    $self->set(-file => $file,-setch => ' 1',-unsetch => ' 0');

    open my $fh, ">$file" or die "Failed to open `$file': $!";
    local $\ = "\n";
    print $fh 'P1';
    print $fh "# $file";
    print $fh $self->get(-width );
    print $fh $self->get(-height );
    print $fh $self->as_string;
  }

I'm aware that the inheritance hierarchy

  Image::Pbm <: Image::Xbm <: Image::Base

is suboptimal and should look like

  Image::Xbm <:
                Image::Bitmap <: Image::Base
  Image::Pbm <:

(That's why I Cc'ed to Mark.) But this change can be done
later and isn't very relevant for namespace discussion.


Steffen

Reply via email to