in reply to Named array indices
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Named array indices (packages)
by choroba (Cardinal) on Aug 06, 2010 at 09:02 UTC | |
by tye (Sage) on Aug 06, 2010 at 15:02 UTC | |
by choroba (Cardinal) on Aug 06, 2010 at 15:14 UTC | |
|
Re^2: Named array indices (packages)
by LanX (Saint) on Aug 06, 2010 at 12:59 UTC |