package Your::Class; our $VERSION= 1.001_001; package Your::Class::_Implementation; BEGIN { require constant; my $offset= 0; for my $member ( qw< _NAME _ADDRESS _PHONE ... > ) { constant->import( $member, $offset++ ); } } sub Your::Class::new { ... $self->[_NAME]= ...; }
If you don't like writing "sub Your::Class::new" instead of "sub new", then you can instead do something like:
... package Your::CLass::_Implementation; ... sub new { ... } ... package Your::Class; BEGIN { require Exporter; for my $method ( qw< new ... > ) { Exporter::import( 'Your::Class:_Implementation', $method ); } }
This also allows you to separate your class methods fom your ojects methods, just FYI.
It isn't difficult to abstract out these tools to make them look prettier.
Note that a C' prefix is a horrible idea:
package Your::Class; ... sub C'Name() { 0; } ... package Something::Completely::Different; ... sub C'Index() { 0; } sub C'Name() { 1; } # Boom! ...
- tye
In reply to Re: Named array indices (packages)
by tye
in thread Named array indices
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |