aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Williams2025-08-20 23:54:32 +0000
committerEmil Williams2025-08-20 23:54:32 +0000
commitd75ac24491b782974517cbff207bfbc17e46bd56 (patch)
tree8ef8dad7f458c24cd10305258d71634d6da5fbdc
parentdf2e0e9da234428306fb933f84e21078dc75020b (diff)
parent98e32923a3622d01b9bcccd2551ab73a55b740c4 (diff)
downloadgorillanest-d75ac24491b782974517cbff207bfbc17e46bd56.tar.xz
gorillanest-d75ac24491b782974517cbff207bfbc17e46bd56.tar.zst
Hopefully Things Are Better Now
-rw-r--r--.gitignore5
-rwxr-xr-xgorillanest.pl.cgi69
-rwxr-xr-xgorillanest.pl.fcgi1
-rw-r--r--lighttpd-cgi.conf1
-rw-r--r--template/index.tt8
5 files changed, 51 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index ee90409..7459f49 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
+nytprof/
*.sqlite3
+*.db
+*.out
config.pl
git/*
-!git/public/.gitkeep
-!git/private/.gitkeep
diff --git a/gorillanest.pl.cgi b/gorillanest.pl.cgi
index 8f688aa..6d01d7c 100755
--- a/gorillanest.pl.cgi
+++ b/gorillanest.pl.cgi
@@ -1,9 +1,19 @@
#!/usr/bin/env perl
+# XXX
+# why are we passing around root like a cheap whore? because root is where things are (f(x) -> y)
+# looking into it, i think we should have a global config object using
+# https://metacpan.org/pod/Readonly fuck read only, constants are for faggots
+#
+# i modified the routing heavily, this is how people do it; very scary
+# pretty clean
+# you must also realize that not all routes are necessarily templates, then they are routed by nginx.
+# it could be a redirect for example, so the original solution would
+# complicate beyond comprehension ACK.
+
use strict;
use warnings;
use CGI;
-use Switch::Back;
use Template;
use URI::Escape;
use Cwd;
@@ -17,7 +27,14 @@ sub info {
warn join(' ', @_);
}
-our $template = Template->new({INCLUDE_PATH => 'template'});
+
+sub serve_template {
+ my $template = Template->new({INCLUDE_PATH => 'template'});
+ my ($template_name, $data) = @_;
+
+ $template->process($template_name, $data)
+ or info("Template: " . $template->error());
+}
# significant dirs only
sub GN::directories {
@@ -37,50 +54,47 @@ sub GN::directories {
# probably should output all repos recursively, currently just outputs list of users
sub GN::index { # /
- my ($root, $dataref) = @_;
- my %data = %$dataref;
+ my ($root) = @_;
+ my %data;
+
my @directories = map { my $i = $_; map { join('/', $i, $_) } @{GN::directories(join('/', $root, $i))} } @{GN::directories($root)};
$data{directories} = \@directories;
if ($data{directories}) { $data{found} = 1; }
- return \%data;
+
+ serve_template("index.tt", \%data);
}
sub GN::user { # /$username/
- my ($root, $dataref) = @_;
- my %data = %$dataref;
+ my ($root, $username) = @_;
+
+ my %data;
my @directories = @{GN::directories(join('/', $root, $data{username}))};
$data{directories} = \@directories;
if ($data{directories}) { $data{found} = 1; }
- return \%data;
+
+ serve_template("index_user.tt", \%data);
}
sub GN::repository { # /$username/$repository
- my ($root, $dataref) = @_;
- my %data = %$dataref;
- $data{found} = 0;
- return \%data;
-}
+ my ($root, $username, $repository) = @_;
-sub serve_template {
- my ($file, @rest) = @_;
- my %vars = @rest ? @rest : ();
-
- $template->process($file, \%vars)
- or info("Template: " . $template->error());
+ die 'not implemented';
}
-my %routes = (
- '/' => sub { serve_template("index.tt", @_) },
- '/~([a-zA-Z0-9_.]+)' => sub { serve_template("index_user.tt", @_) },
- '/~([a-zA-Z0-9_.]+)/([a-zA-Z0-9_.]+)' => sub { serve_template("repository.tt", @_) },
-);
-
my $root = GIT_ROOT;
my $dbfile = DB_FILE;
+
my %data = (
found => 0,
);
+my %routes = (
+ '/' => sub { GN::index($root); },
+ '/~([\w.]+)' => sub { GN::user($root, @_) },
+ '/~([\w.]+)/([\w.]+)' => sub { GN::repository($root, @_) },
+);
+my %route_regex_cache = map { $_ => qr{^$_$} } keys %routes;
+
sub master {
my $cgi = CGI->new;
my %header = (
@@ -91,13 +105,14 @@ sub master {
my $uri = $ENV{'REQUEST_URI'} || '/';
for my $pattern (keys %routes) {
- if ($uri =~ m{^$pattern$}) {
+ if ($uri =~ $route_regex_cache{$pattern}) {
my $handler = $routes{$pattern};
$handler->($uri, $1, $2, $3);
+ return;
}
}
- serve_template("404.tt"); # XXX missing code
+ serve_template("404.tt", {}); # XXX missing code
}
master() if !caller;
diff --git a/gorillanest.pl.fcgi b/gorillanest.pl.fcgi
index 2692877..a9d77c0 100755
--- a/gorillanest.pl.fcgi
+++ b/gorillanest.pl.fcgi
@@ -7,7 +7,6 @@ use Syntax::Keyword::Try;
use FCGI;
use lib '.';
-# BEGIN { require 'config.pl'; }
BEGIN { require 'gorillanest.pl.cgi'; }
try {
diff --git a/lighttpd-cgi.conf b/lighttpd-cgi.conf
index 07b55d7..24df494 100644
--- a/lighttpd-cgi.conf
+++ b/lighttpd-cgi.conf
@@ -15,7 +15,6 @@ setenv.add-environment = (
"PERL5LIB" => env.PERL5LIB
)
-
cgi.assign = (
".pl.cgi" => "/usr/bin/perl"
)
diff --git a/template/index.tt b/template/index.tt
index aa48b16..ff72c95 100644
--- a/template/index.tt
+++ b/template/index.tt
@@ -5,8 +5,12 @@
<body>
<h1>[% title %]</h1>
<h2>[% description %]</h2>
-<ul>[% FOR i IN directories %]<li><a href="/[% i %]">/[% i %]</a></li>[% END %]</ul>
+<ul>
+ [% FOR i IN directories %]
+ <li><a href="/[% i %]">/[% i %]</a></li>
+ [% END %]
+</ul>
<p>one million [% access %] xolatile's</p>
-</body>
[% INCLUDE foot.tt %]
+</body>
</html>