A quick statement first (from the page you get to when you click on use):

Excepting that Module must be a bareword, use is exactly equivalent to

BEGIN { require Module; import Module LIST; }
Now, require is a run-time compilation and use is a compile-time compilation. I've often done something along the lines of
my $moduleName = "Foo::Bar::$var"; require $moduleName;
With appropriate checks on $var, of course!

The real question arises as to whether or not OO Perl should be doing anything with import(). I would say that it shouldn't be, because import() would seem to violate encapsulation. Instead, require would seem to be indicated. And, if all your requires are on top, then it's almost as if you're doing it at compile-time, because they're the first things to be run.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Is use really appropriate in a OO system?
by merlyn (Sage) on Sep 25, 2001 at 20:18 UTC
    In general, the import list for an OO module should be empty, so use is still an appropriate interface.

    However, in some cases, exporting a constructor is practical. For example, the URI module exports a url constructor to make it easier to convert strings to URIs.

    -- Randal L. Schwartz, Perl hacker

Re: Is use really appropriate in a OO system?
by princepawn (Parson) on Sep 25, 2001 at 20:07 UTC
    1. You can  use Module::Name () to prevent the call to import
    2. The import method can be used for any sort of initialization. It does not have to be used to import symbol names into your namespace, though this is most common. For other uses of import see Class:MakeMethods
Re: Is use really appropriate in a OO system?
by chromatic (Archbishop) on Sep 25, 2001 at 23:59 UTC
    import() can be very useful in OO situations. You can use it to do mixins, for example. You can optimize inheritance in a static class hierarchy. If you go crazy with closures and other functional tricks, you can even achieve polymorphism.

    There's are very few shouldn'ts in Perl for good reason -- if you know when they're appropriate, you can often do the impossible.

Using/abusing import
by runrig (Abbot) on Sep 25, 2001 at 20:31 UTC
    Well 'import' is just a name. And its just a subroutine in your package (or in an inherited package). And it can do any number of useful things; it doesn't actually have to export any symbols (offhand, I can think of the '-compile' option for the CGI import list).