package File::Collector::Iterator ; use strict; use warnings; use Carp; use Log::Log4perl::Shortcuts qw(:all); my $collector; # private package variable for storing the File::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); } }