diff options
author | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-05-25 21:19:38 +0000 |
---|---|---|
committer | Malcolm Beattie <mbeattie@sable.ox.ac.uk> | 1997-05-25 21:19:38 +0000 |
commit | 97fcbf9696d4cdc3d47f383b99d9840ccb39c616 (patch) | |
tree | db7f5a92355aa3402f174a0065ca2542147c15ee /lib/Class | |
parent | ae77835f9b08444f73b593d4cdc0758132dbbf00 (diff) | |
download | perl-97fcbf9696d4cdc3d47f383b99d9840ccb39c616.tar.gz |
Fix up integration 5.003->5.004.
p4raw-id: //depot/perl@19
Diffstat (limited to 'lib/Class')
-rw-r--r-- | lib/Class/Fields.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Class/Fields.pm b/lib/Class/Fields.pm new file mode 100644 index 0000000000..4b23e7d731 --- /dev/null +++ b/lib/Class/Fields.pm @@ -0,0 +1,33 @@ +package Class::Fields; +use Carp; + +sub import { + my $class = shift; + my ($package) = caller; + my $fields = \%{"$package\::FIELDS"}; + my $i = $fields->{__MAX__}; + foreach my $f (@_) { + if (defined($fields->{$f})) { + croak "Field name $f already used by a base class" + } + $fields->{$f} = ++$i; + } + $fields->{__MAX__} = $i; + push(@{"$package\::ISA"}, "Class::Fields"); +} + +sub new { + my $class = shift; + bless [\%{"$class\::FIELDS"}, @_], $class; +} + +sub ISA { + my ($class, $package) = @_; + my $from_fields = \%{"$class\::FIELDS"}; + my $to_fields = \%{"$package\::FIELDS"}; + return unless defined %$from_fields; + croak "Ambiguous inheritance for %FIELDS" if defined %$to_fields; + %$to_fields = %$from_fields; +} + +1; |