[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Simple Explanation for @ISA?



Robert Ke <rke@qualcomm.com> writes:
>Sorry to tell you, the @ISA has something to do with OOP.  

It's actually even more confusing than that: While the @ISA mechanism often is
used for OOP, it is not strictly related to it. You can do OOP without @ISA and
use @ISA without OOP.

>It works like the @INC array which stores directories for perl  to search 
>for files in other directories.
>
>@ISA array contains names of classes so Perl could search for methods in 
>other classes.

So far, the explanation is correct (and quite elegant, too). However, your
terminology is more OOP biased than Perl itself in fact is. A more accurate
statement would be:

The @ISA array contains names of *modules* so Perl can search for *subroutines*
in other *modules*.

Stated this way, it becomes clear that @ISA works for OOP, but it also works
without OOP. Some important examples are:

@ISA = qw(Exporter) : All modules which export names do this. A statement such
    as "use xxx(a b c)" causes a subroutine named "import" to be executed, and
    this subroutine is taken from the "Exporter" module.

@ISA = qw(DynaLoader) : All Mac toolbox modules do this to be able to
     dynamically load code fragments (This is done in the "bootstrap" routine).

@ISA = qw(AutoLoader) : This can be used to split up modules and load pieces
     on demand.

Matthias

-----
Matthias Neeracher   <neeri@iis.ee.ethz.ch>   http://www.iis.ee.ethz.ch/~neeri
  "If people are boasting that they use the best tools, you can figure that 
   they can't find any competitive advantage to using those tools, or else
   they wouldn't be presenting them as a competitive advantage." -- Dave Winer