use strict; package Ox::Util; use vars '$VERSION'; $VERSION = '0.01'; sub string_trim { my ($str, $c) = @_; $c ||= ' '; $str =~ s!$c+$!!; return ($str); } 1; use strict; package Ox::File; use vars '$VERSION'; $VERSION = '0.01'; use Ox::Util (); sub fix { my $path = shift || ''; $path =~ s!\\!/!g; $path =~ s!/+!/!g; return $path; } sub enum { my %args = @_; $args{dir} ||= ''; $args{depth} ||= 0; $args{callback} ||= ''; return 0 unless ref $args{callback} eq 'CODE'; return 0 unless -d $args{dir}; $args{dir} = &fix($args{dir}); $args{dir} = Ox::Util::string_trim($args{dir}, '/'); my $handle; if(opendir($handle, $args{dir})) { while(defined(my $entry = readdir $handle)) { next if $entry =~ /^\.\.?$/; my $filename = $args{dir}.'/'.$entry; if(-d $filename and ($args{depth} > 0 or $args{depth} < 0)) { my %copyofargs = %args; $copyofargs{dir} = $filename; $copyofargs{depth}--; enum(%copyofargs); } $args{callback}->($filename) if -f $filename; } closedir($handle); } return (1); } 1;