All pastes #467509 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-02 15:46 UTC
rendered paste body
package Foo;
our %Foo= (
    _text => 'some text',
...
};

sub _classobj {
    my $self  = shift || __PACKAGE__;
    my $class = ref($self) || $self;
    no strict "refs";
    return \%$class;
}

for my $datum (keys %{ _classobj() } ) { 
   *$datum = sub {
       my $self = shift;
       $self = $self->_classobj() unless ref $self;
       $self->{$datum} = shift if @_;
       return $self->{$datum};
   }
}

package Bar;
@ISA = qw("Foo");
our %Bar= (
    _text => 'some other text',
    _also => 'also this one',
...
};

sub _classobj {
    my $self  = shift || __PACKAGE__;
    my $class = ref($self) || $self;
    no strict "refs";
    return \%$class;
}

for my $datum (keys %{ _classobj() } ) { 
   *$datum = sub {
       my $self = shift;
       $self = $self->_classobj() unless ref $self;
       $self->{$datum} = shift if @_;
       return $self->{$datum};
   }
}