Dan Muey wrote:
>
> Sorry for the confusion, I was switching example names on everyone.
>
> I think I've got it.
>
> I've made it object oriented and functional based. (Gulp, kinda scary :-))
>
> I have

This is in your Mymodule.pm presumably?

> package Parent::Module::MyModule;

My only proviso is that in your first post you were using

  use lib '/home/me/modules/';
  use use Parent::Module::MyModule;

in which case your module source should be in

  /home/me/modules/Parent/Module/MyModule.pm

> With simply bare function names like so:
> (IE not Parent::Module::functionname {} so as not to invad namespace) sub 
> funtionname {}

That's exactly the way subclassing should work: remember that the only
access you're supposed to have to a class is through its public
interface. Perl makes it very easy to break rules like this.

> So One can do this:
>
> use Parent::Module::MyModule;
> my $r = Parent::Module::MyModule::functionname($parentobj,$arg);
>
> use Parent::Module::MyModule; qw(functionname);
> my $r = functionname($parentobj,$arg);


Neither of these is the right way to go about things. The first tries to cheat
by pretending to the method function that it's being called as a standard Perl
method call $parentobj->functionname. If you don't want to use it that way it
shouldn't be a method at all.

The second isn't right either. That qw(functionname) is sitting on its own
without making any difference to the world around it. If you had 'use warnings'
it would have told you so. Also you're exporting a method function and calling
it the same way as before.

I'm worried about what your $parentobj is. From its name I would think it's
a Parent::Module object, but your then trying to call a method from your new
subclass on it.

> Or if new() is called each function is "smart" enough to know that the first
> thing is a $self object and not the parent $obj and to use $self->{Parent}
> for the parent $obj.

This doesn't make sense. There should be no 'parent' object, just an object.
There is a parent (base) class and a subclass and all objects should belong
to one or the other. The existence of a $self->{Parent} implies that the
objects can be tree-structured, but this is part of the coding of the module
and nothing to do with class hierarchy.

> use Parent::Module::MyModule;
> my $newobj = new Parent::Module::MyModule($parentobj);
> my $r = $newobj->functionname($arg);
>
> Does that seem about right?

Well yes, it does look about right. But I can't see how you got here from
what's gone before! It still looks like you think you need to pass a
'parent' object to the subclass constructor to create your $newobj. Unless,
like I say, you're creating a fancy object that links to others of the same
type.

> Sorry for the confusion but it's been a fun learning example for me,
> sorry if I made it Monday for you :)

It's always Christmas Day for me Dan!

But I think you need to show us your code. I'm sure you're making things
too hard for yourself. Post it off-group to me if you'd rather and I'll
mark it up.

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to