in reply to Re: Computed "my" declarations?
in thread Computed "my" declarations?

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.

Replies are listed 'Best First'.
Re^3: Computed "my" declarations?
by diotalevi (Canon) on Oct 26, 2005 at 23:20 UTC

    Better than a timestamp, store another hash in a key named after your package. In your Foo->new method, store a hash ref.

    sub foo { my $self = shift; my $data = $self->{+__PACKAGE__}; $data->{...} }
Re^3: Computed "my" declarations?
by jdhedden (Deacon) on Oct 27, 2005 at 20:36 UTC
         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.