This in itself isn't bad OO programming, and it doesn't defeat the purpose of OO. *However*, what if the callback then wants to access the cache? In your current scheme it would have to directly access$callback->($self);
That's not good: you don't want some random callback function altering your object's attributes. So what you should do is, your class should provide some object methods to manipulate the cache. For example:$self->{CACHE}
To be used in a callback function like this:sub add_to_cache { my $self = shift; my $alias = shift; my @files = shift; push @{ $self->{CACHE}->{$alias} }, @files; }
Is this what you had in mind? You no longer have to muck around with your object's CACHE attribute.$cache->add_to_cache(ALIAS, @files_in_dir);
Notice also that, instead of appending to a string, as you do, I'm pushing the directory name onto an array. This will get around your problem of filenames with spaces.
In reply to Re: Re: RE: RE: Scoping and Objects
by btrott
in thread Scoping and Objects
by radman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |