Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Package Name and Inheritance

by erroneousBollock (Curate)
on Nov 14, 2007 at 09:57 UTC ( [id://650712]=note: print w/replies, xml ) Need Help??


in reply to Package Name and Inheritance

The following is a fairly typical example of a simple constructor for the Stuff class:

package Stuff; sub new { my $class = shift; my %args = @_; bless { fooAttr => $args{foo}, barAttr => $args{bar}, }, $class; } 1;

If you bless the attribute hash into 'Stuff' rather than $class, a subclass of Stuff (say Junk) which calls the super-class's constructor will be blessed into the Stuff package instead of the Junk package.

If Junk adds/overrides any methods, they won't be called.

Another problem is that it's much harder to maintain a class if the classname is sprayed all over its constituent modules.

-David

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 19:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found