On Sunday 19 December 2004 20:48, JupiterHost.Net wrote: > Hello group, Hi,
> I'm trying to subclass a module (at least I think its what is called > subclassing...) I'm not sure, but I think subclassing is the appropriate term for this ;-) > 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 > I think what you want to do is to create an own class that inherits from GD::Image. In Perl (5), a class is basically a package, so you've been on the right track when you wrote this sub starting with sub GD::Image::Foo { ... Now just create a new file called Foo which you put into the folder GD/Image, so that it can be found by perl. This class should probably look similar to this (UNTESTED): ############################################## #!/usr/bin/perl # file: GD/Image/Foo.pm # the package name is the class name package GD::Image::Foo; use strict; use warnings; use GD; # this declares that you want to inherit from GD::Image our @ISA = qw(GD::Image); sub Foo { my $self = shift; # work with the image } ############################################## Now you should be able to use it instead of the usual image: [..] > I'd like that to be: > > #!/usr/bin/perl > > use strict; > use warnings; > #use GD; I think you don't need this line any more because of the next one. > use GD::Image::Foo; # has sub GD::Image::Foo {} in it ... > > # my $image = GD::Image->new(42,21); You've got to instantiate an object of your new class instead - try: my $image = GD::Image::Foo -> new(42,21); > my $white = $image->colorAllocate(255,255,255); > $image->transparent($white); > > $image->Foo(1,5,9); > > Any docs/ideas most appreciated! > > TIA I'm not very experienced with OOP in perl, but I think this should be it - if you got the Camel book at hand, take a look into the OOP chapter. It's very comprehensible (and funny). If you do not have the camel book, give it to yourself as a christmas present ;-) HTH, Philipp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>