public
Created

Continuity based browser "deep ls"

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.