in reply to Perl Module Education

Side note: you don't normally need a & in front of a subroutine name anyhow. In fact, adding one changes the semantics slightly. But the thing to read is the following excerpt from le manpage du jour, perldoc perlop:

"`->'" is an infix dereference operator, just as it is in C and C++. If the right side is either a `[...]', `{...}', or a `(...)' subscript, then the left side must be either a hard or symbolic reference to an array, a hash, or a subroutine respectively. (Or technically speaking, a location capable of holding a hard reference, if it's an array or hash reference being used for assignment.) See the perlreftut manpage and the perlref manpage. Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name). See the perlobj manpage.

Most modules use the standard Exporter module, which provides a standardized import mothod, although you are free to write your own. Read perldoc Exporter and poke around in a few of your favorite modules to see how Exporter gets used.

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Replies are listed 'Best First'.
overriding import; good or bad?
by t'mo (Pilgrim) on May 19, 2001 at 02:50 UTC
    ...you are free to write your own...

    Funny, but I was just reading about that this afternoon in notes from a talk given by our very own Dominus. Although I must admit when I read it, I wondered if it's a GoodIdea™ to 'roll your own' version of Exporter, or conversely, if it's a BadIdea™. Any comments?

    /me goes off and checks 'import' in SuperSearch, just in case there has been previous discussion on this topic...

    Good thing I checked. Here's why:

    • Checking gave me time to think more about another question that is a level above the question I asked: "Given my current programming experience level, should I even be asking if X is a Good/Bad Thing ™?" Perhaps I should invest more time learning to work with what exists before reinventing the wheel; perhaps by un-asking the question, I have learned something...
    • I found this node which, though it doesn't directly answer my Good/Bad Thing™ question, brings up some good points.

    Still, I can't resist being curious, so if there are any ideas on whether or not writing your own import function, rather than using Exporter, is a Good/Bad Thing™, I'd be curious to hear. :-)

    Update: Two things...

    1. Changed title of my post.
    2. I don't mean to imply by asking about "good/bad" that I am questioning Dominus' judgement. :-)
Re: Re: Perl Module Education
by radman (Novice) on May 18, 2001 at 22:51 UTC

    Ah ha! A package is a class and a class is a package, thus when you say 'Module->import()' you're calling a class method. I understand now. Wisdom ist gut.

    This has been R A D...