package List; use strict; use warnings; use vars qw(@ISA @EXPORT_OK $VERSION); use File::Spec qw(catfile); use Carp; use Cwd qw(cwd abs_path); require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(list); $VERSION = '0.99'; ###################################################################### # object interface sub new { my ($class, $stream, $path, ) = @_; $stream = \*STDOUT unless @_ > 1; $path = cwd unless @_ > 2; my $self = { stream => $stream, path => File::Spec->canonpath($path), }; bless $self, $class; return $self; } sub list { my ($self, $dir, $level) = @_; $dir = $self->{path} unless @_ > 1; $level = 0 unless @_ > 2; if ( opendir( DIR, $dir)) { $level++; map { my $fullfile = File::Spec->catfile( $dir, $_ ); if (-d $fullfile) { $self->list ( $fullfile, $level ); } my $str = $self->{stream};# ref to the stream print $str $fullfile; ## problem?? } File::Spec->no_upwards( readdir( DIR ) ); } else { warn "$dir : opendir failed: $!\n"; } close DIR; } sub stream_to{ my ($self, $strm) = @_; $strm = \*STDOUT unless @_ > 1; $self->{stream} = $strm; } sub look_in { my ($self, $path) = @_; $path = cwd unless @_ > 1; $self->{path} = $path; }