☞ | ![]() ![]() |
33 |
Sometimes you have to store the same kind of data in two different places
How to put the same interface on two different things?
Oh yeah, that's why we have functions:
sub direct_observers { my $self = shift; if (ref($self)) { # Get object member return $self->{$self->key} ||= []; } else { no strict 'refs'; return \@{$self->classvar}; # Get package variable } }
Now instead of:
push @{$O{$self}}, ...;
We use:
push @{$self->direct_observers}, ...;
☞ | ![]() |
☞ |