Ok, I think I might be on to something good...or it could be colossally stupid, I'm not sure which. If I could indulge your attention for a little bit more, I'd appreciate it.
So check this out:
# prints out short name of all "txt-files"
$da->bundle_txt_files->do->print_short_names;
And here is the iterator built using your suggestions (I changed the "all" method name to "do," which seemed to make more sense):
package File::Collector::Iterator ;
use strict;
use warnings;
use Carp;
use Log::Log4perl::Shortcuts qw(:all);
my $collector; # private package variable for storing the Fi
+le::Collector
sub print_short_names {
my $s = shift;
print $collector->{files}{$s->selected_file}{short_path} . "\n"; #
+ uses the File::Collector object to look up short path
}
sub new {
my $class = shift;
$collector = shift; # new gets passed the $collector from File:
+:Collector AUTOLOAD
bless [@_], $class;
}
sub next {
my $self = shift;
shift @$self;
return $self->[0];
}
sub selected_file { (shift)->[0] }
# do method of executing methods on child classes
sub do {
my $self = shift;
bless \$self, 'File::Collector::Iterator::All';
}
{
package File::Collector::Iterator::All;
use Log::Log4perl::Shortcuts qw(:all);
sub AUTOLOAD {
our $AUTOLOAD;
my $self = shift;
my @method = split /::/, $AUTOLOAD;
my $method = pop @method;
$$self->$method(@_) while ($$self->next);
}
}
What do you think? Is this a good solution?