Re^2: Subclassing, done right?
by isync (Hermit) on Aug 06, 2010 at 16:32 UTC
|
I think, you've already solved it.
I was already unsure if I need to use the whole slew of modules Net::DAV::Server uses, but with my thin knowledge of subclassing, I thought using "use base" would just like a "use <some module>" magically import/load all the used modules as well.
Your post now indicates that this is not so.
I did not post the actual error message in the first place as I though it wouldn't be helpful, but as I remember, it also pointed to the piece of code you are referring to. I am not actually receiving an error, the whole thing simply is returning an error. Sorry, but debugging helpers do not provide more insight into the actual output, yet.
So please confirm for me as a learning monk: "use base" will only magically import functions for me, used modules need to be repeated in the wrapping module, here Foo.pm, right? | [reply] [d/l] [select] |
|
|
If you look at the source code for base or parent or read perltoot, you will find that inheritance in Perl does not work by copying subroutines. While it is conceptually not very far from copying the subroutines, actually Perl goes searching for methods of that name in the packages listed in @ISA until it finds one. No importing of subroutines is done.
| [reply] [d/l] |
|
|
After duplicating the module loads in my wrapping module, thus dumbly expecting my copy and paste to work, I now know - it doesn't work..
| [reply] |
|
|
So, maybe you'd like to help us help you better?
Posting the actual error message you get and the actual script you write will maybe let us help you better.
| [reply] |
|
|
Re^2: Subclassing, done right?
by isync (Hermit) on Aug 06, 2010 at 17:06 UTC
|
Currently, I am looking into Net::DAV::Server's new() function, which is where the executions seems to take the wrong path due to some variable being filled differently when working as a subclass..
Investigating...
Update: could extract an error, its in new()'s eval:
"Undefined subroutine &Foo::_dav_child called at Foo.pm line 164" which is in my copy and pasted Foo.pm::propfind().
Why didn't use base import the _dav_child() function??
package Foo;
use base Net::DAV::Server;
sub propfind {
# copy of the original propfind() from Net::DAV::Server
# do something
_dav_child(soemthing);
}
| [reply] [d/l] |
|
|
| [reply] |
Re^2: Subclassing, done right?
by isync (Hermit) on Aug 06, 2010 at 17:45 UTC
|
Exactly, when I duplicated the _dav_child subroutine in my Foo.pm wrapper module, it worked.
Strange, as pertoot sais about subs with an underscore: "But this distinction is not enforced by Perl itself."
But when it comes to use base, Perl handles these subs different than the rest... So it's a rule, not a style convention... Lesson learned. | [reply] [d/l] |
|
|
base doesn't enter into it; all use base does (handwaving slightly here) is use the named module and diddle the using module's @ISA. Since Net::DAV::Server doesn't use Exporter and has no special import sub of its own doing anything similar, nothing (underscore or no) gets imported into the using module's namespace.
Update: I just re-read your last paragraph of your original question and I think I see what you're misunderstanding:
Perl inheritance (what base sets up) only affects method calls, not subroutine calls. Since the call is made as a normal subroutine call and not as a method call on an instance inheritance and @ISA never enters the picture.
That clear anything up?
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] [d/l] [select] |
|
|
It did.
And I think I must admit that my knowledge of perl internals, esp. ISA and import/export stuff is still, at least, shaky...
Thank you all!
| [reply] |