JupiterHost.Net wrote:
Hello group,

I'm trying to subclass a module (at least I think its what is called
subclassing...)

This example below works but I'd like to package GD::Image::Foo in its
own module, how would I go about doing that? perldoc perlmod and
perlmodlib didn't seem to address that issue unless of course I'm
confused which is most likely the case ;p

#!/usr/bin/perl

use strict;
use warnings;
use GD;

my $image = GD::Image->new(42,21);
my $white = $image->colorAllocate(255,255,255);
$image->transparent($white);


$image->Foo(1,5,9);

sub GD::Image::Foo {
  my $im = shift;
  # use @_ and $im-> here
}

I'd like that to be:

#!/usr/bin/perl

use strict;
use warnings;
use GD;
use GD::Image::Foo; # has sub GD::Image::Foo {} in it ...

my $image = GD::Image->new(42,21);
my $white = $image->colorAllocate(255,255,255);
$image->transparent($white);

$image->Foo(1,5,9);

Well, you can't do it exactly like that. What you want is to create a new class (say, My::GD::Image) that extends GD::Image like this:


  package My::GD::Image;

  use base qw(GD::Image);

  sub Foo {
      my $image = shift;
      ...blah...
  }

  1;

Then in the main program...

  use My::GD::Image;

  my $image = My::GD::Image->new(42,21);
  my $white = $image->colorAllocate(255,255,255);
  $image->transparent($white);
  $image->Foo(1,5,9);

HTH


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to