perl5ever has asked for the wisdom of the Perl Monks concerning the following question:
Here's an example of what's going on. A module X might look like this:
However in this case X never creates objects of class Order - it merely has a subroutine which expects an Order object as a parameter. Therefore use Order; here is not necessary. The caller of X::doSomething might have to use Order; to create the argument to doSomething.package X; use Order; sub doSomething { my ($self, $order) = @_; # $order is an Order object ... $order->some_method(...); }
In thinking about the problem I've come up with this general rule about using use: only use modules whose name space your module directly references. Just because your module interacts with objects of a certain class doesn't mean it needs to pull in that class.
Of course for every rule there are always exceptions. And there are a lot of different ways in which use is used in perl. What do you think?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: general rule for using use
by moritz (Cardinal) on Apr 08, 2009 at 20:04 UTC | |
by perl5ever (Pilgrim) on Apr 08, 2009 at 22:38 UTC | |
by targetsmart (Curate) on Apr 09, 2009 at 05:38 UTC | |
by drench (Beadle) on Apr 09, 2009 at 17:48 UTC | |
by moritz (Cardinal) on Apr 19, 2009 at 11:36 UTC | |
|
Re: general rule for using use
by ikegami (Patriarch) on Apr 08, 2009 at 21:28 UTC | |
|
Re: general rule for using use
by JavaFan (Canon) on Apr 09, 2009 at 09:26 UTC | |
|
Re: general rule for using use
by dsheroh (Monsignor) on Apr 09, 2009 at 21:54 UTC |