Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Possibly Stupid OOP question

by dsheroh (Monsignor)
on Feb 27, 2008 at 04:06 UTC ( [id://670473]=note: print w/replies, xml ) Need Help??


in reply to Possibly Stupid OOP question

All classes are in the same monolithic source file. USE doesn't appear to like that and searches for actual .pm files...

That is correct. Since packages almost always have a one-to-one relationship with .pm files which share the same name, it's easy to start thinking of them as interchangable, but they're not.

use specifies a file to read, no more and no less. The package(s) contained within that file are defined solely by the package statement(s) it contains.

For example, if you have a file named Foo.pm containing

package Bar; use strict; use warnings; sub hi { print "Hello, world!\n"; } 1;
then you would load its contents with use Foo, but execute them with Bar::hi. This is, obviously, a little confusing in most cases, which is why the convention of using the same name for the file and the package exists. But it's just a convention, not something enforced (or even recognized) by the language.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found