Created
June 14, 2011 04:22
-
-
Save jberger/1024315 to your computer and use it in GitHub Desktop.
Continuity based browser "deep ls"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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