I don't want to use a hash key like 'name' because other classes in the hierarchy may already be using that. So I will use __PACKAGE__ . '::name' instead to avoid the conflict. But I would rather not have to write that every time I reference the value of the field. So I am trying to declare $name with value __PACKAGE__ . '::name', $timestamp with value __PACKAGE__ . '::timestamp', etc. so that I can refer to my package's fields with the simpler $self->{$name}.
The question was how to do that without having to repeat the list of field names with my ($name, $timestamp, ...) = map {...} ('name', 'timestamp', ...);
Thanks, A.C., oops, pm not /. so I guess that's A.M. | [reply] [d/l] [select] |
sub foo {
my $self = shift;
my $data = $self->{+__PACKAGE__};
$data->{...}
}
| [reply] [d/l] |
I don't want to use a hash key like 'name' because other
classes in the hierarchy may already be using that.
You should strongly consider converting over to using inside-out objects which avoids this hassle altogether. Start by looking at Class::Std.
Remember: There's always one more bug.
| [reply] |