Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Modules: Building blocks for the Daft Adventure

by davorg (Chancellor)
on Jun 12, 2001 at 15:47 UTC ( [id://87776]=note: print w/replies, xml ) Need Help??


in reply to Modules: Building blocks for the Daft Adventure

In RPG/DND.pm

package RPG::DND; use Exporter; use vars qw(@ISA @EXPORT_OK); @ISA = qw(Exporter); @EXPORT_OK = qw(modifier); sub modifier { int($_[0]/2)-5 }; 1;

In another_script.pl

use RPG::DND qw(modifier); # lots of code modifier($value); # lots of other code
--
<http://www.dave.org.uk>

Perl Training in the UK <http://www.iterative-software.com>

Replies are listed 'Best First'.
Re: Re: Modules: Building blocks for the Daft Adventure
by Tiefling (Monk) on Jun 12, 2001 at 15:52 UTC
    Many thanks, davorg! That looks like the Way to Do It I was looking for. Dare I ask what the @ISA does? I've seen @ISA in connection with OO, and one of these days I'll use it myself in that context. But what is its function in a Module?

    Tiefling, seeking enlightenment

    -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GAT d++ s:- a-- C++ UL P++ L++(+) E? W+(++) N+ o? K w+(--) !O M- V? PS+ PE- Y PGP- t+ 5 X+ R+++ tv- b+++ DI++++ D+ G+ e++ h!(-) y +? ------END GEEK CODE BLOCK------

      @ISA does the same thing here that it does in an OO module. It defines other modules that Perl should search for subroutines that you don't define in your module.

      For example, in this case use Module is (almost) the same as:

      require Module; Module::import;

      So Perl tries to call the import function in your module. Your module doesn't have an import function so Perl searches the modules in @ISA and calls the first instance of import that it finds. This is in Exporter. Exporter::import does all sorts of clever things and exports the contents of your @EXPORT_OK array into the calling package.

      Update: Ridiculous typo corrected. Thanks to ryddler.

      --
      <http://www.dave.org.uk>

      Perl Training in the UK <http://www.iterative-software.com>

        Your module doesn't have an import function so Perl searches the modules in @INC and calls the first instance of import that it finds.

        I'm wondering if you meant to say:

        Your module doesn't have an import function so Perl searches the modules in @ISA and calls the first instance of import that it finds.


        ryddler

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://87776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-28 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found