develooper Front page | perl.perl5.porters | Postings from October 2016

Re: [perl #129967] [PATCH] Add @ISA to perlvar

Thread Previous | Thread Next
From:
Hauke D
Date:
October 31, 2016 11:01
Subject:
Re: [perl #129967] [PATCH] Add @ISA to perlvar
Message ID:
e8e32394-d528-4043-296f-44508cd80466@zero-g.net
Hi,

On 31.10.2016 06:39, Father Chrysostomos via RT wrote:
 > On Sun Oct 30 17:51:24 2016, tonyc wrote:
 >>
 >> +It is possible to manually set C<@ISA>, but it is recommended to use
 >> +L<parent> to declare parent classes.
 >>
 >> Is it recommended?
 >
 > By some and not by others.

I copied that wording from perlobj: "It is possible to manually set 
@ISA, and you may see this in older Perl code. Much older code also uses 
the base pragma. For new code, we recommend that you use the parent 
pragma to declare your parents. This pragma will take care of setting 
@ISA. It will also load the parent classes and make sure that the 
package doesn't inherit from itself."

But that could certainly be toned down, see updated text below.

 >> This pragma will take care of setting
 >> +C<@ISA> and will also load the parent classes and make sure that the
 >> +package doesn't inherit from itself.
 >>
 >> Setting @ISA directly also checks for recursive inheritence:
 >>
 >> $ ./perl -e 'package Foo; our @ISA = "Bar"; package Bar; our @ISA =
 >> "Foo";'
 >> Recursive inheritance detected in package 'Bar' at -e line 1.

Having never set @ISA manually (at least as far back as I can 
remember...) I did not know that, thanks!

 > I think it would be better for perlvar to begin by explaining what
 > the variable does and what it is for, and *then* also mention that
 > parent.pm *can* be used to set it.

The patch begins with an explanation of the variable's purpose which I 
again mostly copied & adapted from perlobj. It doesn't discuss MRO but 
links to perlobj. I'll gladly take any suggestions there.

Updated suggestion:

---8<---
Each package contains a special array called C<@ISA> which contains a 
list of that class's parent classes, if any. This array is simply a list 
of scalars, each of which is a string that corresponds to a package 
name. The array is examined when Perl does method resolution, which is 
covered in L<perlobj>.

It is possible to manually set C<@ISA>, or you can use L<parent> to load 
and declare parent classes. Alternatively there is the L<base> pragma, 
but that is discouraged unless you're also using the L<fields> pragma.
--->8---

If that's better I'd be happy to produce a new patch.

Thanks, Regards,
-- Hauke D


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About