Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • The reason for not discussing that is that generally, you shouldn't mix exported functions and methods. That's because a method really expects to be called with an object as its first argument, which is less likely to happen correctly if you say method($obj) instead of $obj->method(). Also, you don't get inheritance because you're not going through method dispatch.

    I'm sure there are a few cases where you might want to export things, but generally, I'd think twice before pulling in Exporter.


    • You lost me. I understand the $obj->method thing, but what I didn't understand and had hoped Dave would get into was the whole Exporter thing. What is it, why is it used, etc...

      Some objects are written such that when you use them, you have to import the methods you'll be using, like:

      use My::Module qw/ method1 method2 /;

      And others are written so you can just say:

      use My::Module;

      And then you automatically have access to the methods.

      • I think you're getting confused between ordinary functions and OO code (methods). If you don't call it with an arrow, it's not a method, it's a function (with the annoying exception of the indirect method call syntax, but don't worry about that yet).

        When you use a module, you're actually using OO behind the scenes, even though the results aren't usually OO. What happens is that Perl ends up calling the import() method of the named class and passing it the list that you have supplied.

        What makes it a me