in reply to Automated Slurp

For argument's sake,

{ no strict 'refs'; *main::slurp = \&Slurp::slurp; }

could also be written as an export:

use Exporter; our @ISA = qw( Exporter ); our @EXPORT = qw( slurp );

or better, an export on request:

use Exporter; our @ISA = qw( Exporter ); our @EXPORT_OK = qw( slurp );

Replies are listed 'Best First'.
Re^2: Automated Slurp
by afoken (Chancellor) on Jan 03, 2010 at 09:10 UTC

    Not "also be written", but "better be written":

    Not every code that would use this module wants the slurp routine aliased as main::slurp. Most times, calling code wants the slurp routine either in its own namespace or nowhere except in the Slurp:: namespace. Using Exporter (or one of the alternatives) would allow that, the original code doesn't. It should at least call the caller method to find out into which namespace the alias should be exported instead of blindly assuming main::. And it should create the alias inside the import routine, allowing use Slurp () to load the module without creating any alias.

    Exporter is a huge load of code, and sometimes just overkill. The "tricks" from the Manual Exporting section of the Teflon Tape article shows how to export with less code. On the other hand, since so many modules use the Exporter, it is already in memory without extra costs most of the times, so writing own exporting code costs more than just using the Exporter and may create new bugs.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^2: Automated Slurp
by urthwrm (Novice) on Jan 03, 2010 at 00:10 UTC
    I havnt had a thorough look at Exporter yet, but it does seem like the more elegant solution, thanks!
      seem like the more elegant solution

      For what you are doing in your code, it isn't. Why substitute 500 lines of code for 4?

      Errors compound geometrically with the number of lines of code.

      Exporter is fine if you need its facilities. It's overhead, complexity and a drag on maintenance if you do not.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.