Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Extending a class (corrected)

by Athanasius (Archbishop)
on Apr 14, 2016 at 08:00 UTC ( [id://1160377]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Extending a class (updated)
in thread Extending a class

Hello betacentauri,

But I was expecting that, since $self was a MyPackage object, its progeny would be the same species...

Yes, they would be. So within your sub Bar, $self is an instance of class MyPackage; and since MyPackage ISA SVG, $self ISA SVG too.

But don’t be fooled by the names: as far as Perl is concerned, SVG and SVG::Element are separate and unrelated classes! When Perl sees use SVG; (or use parent 'SVG';), it looks for a module named SVG.pm in the directories contained in the global variable @INC. But when it sees use SVG::Element;, it looks in @INC for a directory named SVG, and then within that directory for a module named Element.pm. And that’s it! Apart from their namespaces, the two modules are independent of each other. See perlmod#Packages.

Of course, these classes are related conceptually (i.e., in the programmer’s mind), which is why their author included them both in the SVG distribution (which also contains classes SVG::DOM, SVG::Extension, and SVG::XML); but Perl itself knows nothing of this relationship.

Update: The above is true in the general case. But in this specific case, it turns out that the module SVG.pm actually begins as follows:

package SVG; use strict; use warnings; use SVG::XML; use parent qw(SVG::Element SVG::Extension);

— so an object of class SVG ISA SVG::Element as well. Thanks to haukex for the heads-up.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1160377]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found