in reply to Re: RE: RE: Scoping and Objects
in thread Scoping and Objects

Ah, so you want your callback to have access to your object. Well, that's easy: yes, pass in the $self object:
$callback->($self);
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
$self->{CACHE}
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:
sub add_to_cache { my $self = shift; my $alias = shift; my @files = shift; push @{ $self->{CACHE}->{$alias} }, @files; }
To be used in a callback function like this:
$cache->add_to_cache(ALIAS, @files_in_dir);
Is this what you had in mind? You no longer have to muck around with your object's CACHE attribute.

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.