Forked from tcoxon/Reddit clone in 4 lines of perl.
Created
February 4, 2010 21:23
-
-
Save mgruberman/295122 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/perl4 | |
# Horrible, horrible, horrible edit of someone's | |
# even more horrible "reddit clone in 4 lines of perl". | |
use CGI ':standard'; | |
$dir = File::Basename::dirname( $0 ); | |
chdir $dir; | |
CGI::import_names("x"); | |
if ( $x::t ) { | |
open $f, '>', "$x::t.r"; | |
print { $f } | |
"$x::l$/$x::v$/" | |
. ( $x::i | |
? $x::i | |
: localtime ); | |
close $f; | |
CGI::delete(qw( t l v i )); | |
$x::t = 0 | |
} | |
my @all_posts = glob( | |
$x::s | |
? "*$x::s*.r" | |
: "*.r" | |
); | |
header(), | |
start_html(); | |
start_form(), | |
textfield( -name => 's', -value => 'search' ), | |
submit(), | |
end_form(); | |
start_form(), | |
textfield( -name => 't', -value => 'title'), | |
textfield( -name => 'l', -value => 'link'), | |
hidden( -name => 'v', -value => 0 ), | |
submit(), | |
end_form(); | |
ul( | |
li( [ sort { | |
$s = sub{ | |
$_ = $_[0]; | |
s~<.*?>~~g; | |
$_ | |
}; | |
$s->($b) cmp $s->($a) | |
} | |
map { | |
open $f, '<', $_; | |
my @a = <$f>; | |
chomp @a; | |
m/(.*)\.r/; | |
( a { -href => "?t=$1&l=$a[0]&i=$a[2]&v=" | |
. ( $a[1] + 1 ) }, | |
"^" ) | |
. $a[1] | |
. ( a { -href => "?t=$1&l=$a[0]&i=$a[2]&v=" | |
. ( $a[1] - 1 ) }, | |
"v" ) | |
. " " | |
. ( a { -href => $a[0] }, | |
$1 ) | |
. br() | |
. small "added: $a[2]" | |
} | |
@all_posts ] ), | |
end_html(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment