package Array::Class; # Copyright (c) 1999 Greg Bacon. All Rights Reserved. # This program is free software; you may redistribute or # modify it (perhaps both) under the same terms as Perl # itself. =head1 NAME Array::Class - Declare superclass and attributes of a class =head1 SYNOPSIS # in a base class use Array::Class undef, qw( ATTR_1 ... ATTR_N ); # in a derived class use Array::Class 'My::Super::Class', qw( ATTR_1 ... ATTR_N ); =head1 DESCRIPTION C is a convenience module for declaring the superclass and attributes of a class whose instances are arrays. The inheritance graph must be a tree, so this approach will not work with multiple inheritance. See "Perl Heresies: Building Objects Out Of Arrays" in Issue 13 of The Perl Journal (Spring 1999) for a more detailed description. The head of the import list is the name of the superclass of the calling class. The tail is the list of attributes used by instances of the calling class. =head1 BUGS This approach does not work with multiple inheritance. =head1 AUTHOR Greg Bacon ECE Copyright (c) 1999 Greg Bacon. All Rights Reserved. This program is free software; you may redistribute or modify it (perhaps both) under the same terms as Perl itself. =head1 VERSION Version 1.00 (March 1999) =head1 SEE ALSO "Perl Heresies: Building Objects Out Of Arrays". I #13. =cut use strict; use vars '$VERSION'; $VERSION = '1.00'; sub import { my($me,$super,@attr) = @_; my $pkg = caller; my $i; { no strict 'refs'; @{ $pkg . '::ISA' } = $super if $super; *{ $pkg . '::ATTRIBUTES' } = sub { my $class = shift; my @a; if ($super) { @a = (&{ $super . '::ATTRIBUTES' }, @attr); } else { @a = @attr; } @a; }; $i = $super ? &{ $super . '::ATTRIBUTES' } : 0; } for (@attr) { eval "sub ${pkg}::$_ () { $i }"; $i++; } } sub export { # NOP } 1;