Skip to content

@jberger /gist:1024315
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Continuity based browser "deep ls"
#!/usr/bin/env perl
use strict;
use warnings;
use Continuity;
use File::chdir;
my $server = Continuity->new(port => 8080);
$server->loop;
sub main {
my $req = shift;
$req->print( <<END );
<form method=POST>
Enter a directory name:
<input name=dir>
<input type=submit>
</form>
END
$req->next;
my $dir = $req->param('dir');
$req->print(
walk_dir($dir)
);
}
sub do_something {
return shift . "</br>";
}
sub walk_dir {
my $dir = shift;
local $CWD = $dir;
opendir(my $dh, $CWD);
my $return = "In: $CWD</br>";
while (my $entry = readdir $dh) {
next if ($entry =~ /^\.+$/);
if (-d $entry) {
$return .= walk_dir($entry);
} elsif (-f $entry) {
$return .= do_something($entry);
}
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.