in reply to Dumping Tie Objects

Nevermind. The reason why the Dumper line didn't work because I have not defined the FIRSTKEY and NEXTKEY functions.
sub FIRSTKEY { my ($self) = @_; each %{ $self->{'value'} }; } sub NEXTKEY { my ($self) = @_; each %{ $self->{'value'} }; }
Once I added the two functions, then the Dumper worked. But interestingly, how come Perl didn't tell me that the two functions need to be defined at all?

Replies are listed 'Best First'.
Re^2: Dumping Tie Objects
by AnomalousMonk (Archbishop) on Nov 21, 2009 at 00:15 UTC
    I think (perhaps more knowledgeable monks can confirm) that the  FIRSTKEY function needs to be defined such that it always returns the first key of the hash. As it is, it's the same as  NEXTKEY and only returns the first key upon the first iteration or when iteration wraps around to the beginning again.

    Try (untested):

    sub FIRSTKEY { my ($self) = @_; scalar keys %$Self; return each %{ $self->{'value'} }; }
    Update: keys resets the internal iterator of a hash. In void context, this happens with no other overhead, so the use of scalar above is only for the purpose of self-documentation.

    Also: On second thought, I would be inclined to implement  FIRSTKEY in terms of  NEXTKEY (also untested):

    sub FIRSTKEY { my ($self) = @_; keys %$Self; return $self->NEXTKEY; }