diff options
author | Gisle Aas <gisle@aas.no> | 1998-06-29 14:36:09 +0200 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-06-30 05:17:33 +0000 |
commit | f1192ceea6b2a126a4ff3254f91c2bc47c361c71 (patch) | |
tree | 2bca20552574a90634d783266fcb9ce8a3d90b2c /lib/base.pm | |
parent | 25eaa2138d60ea820620e1b1324f90a6b4f4adcd (diff) | |
download | perl-f1192ceea6b2a126a4ff3254f91c2bc47c361c71.tar.gz |
Re: [PATCH] Simplified magic_setisa() and improved fields.pm
Message-Id: <m367hk4hra.fsf@furu.g.aas.no>
p4raw-id: //depot/perl@1266
Diffstat (limited to 'lib/base.pm')
-rw-r--r-- | lib/base.pm | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/base.pm b/lib/base.pm index 4c4fb8b86b..3500cbfb89 100644 --- a/lib/base.pm +++ b/lib/base.pm @@ -5,7 +5,6 @@ base - Establish IS-A relationship with base class at compile time =head1 SYNOPSIS package Baz; - use base qw(Foo Bar); =head1 DESCRIPTION @@ -18,11 +17,19 @@ Roughly similar in effect to push @ISA, qw(Foo Bar); } +Will also initialize the %FIELDS hash if one of the base classes has +it. Multiple inheritance of %FIELDS is not supported. The 'base' +pragma will croak if multiple base classes has a %FIELDS hash. See +L<fields> for a description of this feature. + +When strict 'vars' is in scope I<base> also let you assign to @ISA +without having to declare @ISA with the 'vars' pragma first. + This module was introduced with Perl 5.004_04. -=head1 BUGS +=head1 SEE ALSO -Needs proper documentation! +L<fields> =cut @@ -30,6 +37,7 @@ package base; sub import { my $class = shift; + my $fields_base; foreach my $base (@_) { unless (defined %{"$base\::"}) { @@ -44,9 +52,26 @@ sub import { "which defines that package first.)"); } } + + # A simple test like (defined %{"$base\::FIELDS"}) will + # sometimes produce typo warnings because it would create + # the hash if it was not present before. + my $fglob; + if ($fglob = ${"$base\::"}{"FIELDS"} and *$fglob{HASH}) { + if ($fields_base) { + require Carp; + Carp::croak("Can't multiply inherit %FIELDS"); + } else { + $fields_base = $base; + } + } + } + my $pkg = caller(0); + push @{"$pkg\::ISA"}, @_; + if ($fields_base) { + require fields; + fields::inherit($pkg, $fields_base); } - - push @{caller(0) . '::ISA'}, @_; } 1; |