aboutsummaryrefslogtreecommitdiff
path: root/perl/cgi.pl
diff options
context:
space:
mode:
authorEmil Williams2025-08-21 09:35:27 +0000
committerEmil Williams2025-08-21 09:35:27 +0000
commit0230b7bd2e4dddac99218d69076ac8da550a57a3 (patch)
treebf3992111bb838a1193052ea50d89437f2c2774a /perl/cgi.pl
parentc257a3cbe2e83ebefef330d64c4ac7fc94ffc8a5 (diff)
downloadgorillanest-0230b7bd2e4dddac99218d69076ac8da550a57a3.tar.xz
gorillanest-0230b7bd2e4dddac99218d69076ac8da550a57a3.tar.zst
Isolate Things Pt. 1
Diffstat (limited to 'perl/cgi.pl')
-rwxr-xr-xperl/cgi.pl45
1 files changed, 26 insertions, 19 deletions
diff --git a/perl/cgi.pl b/perl/cgi.pl
index b802979..c5cd950 100755
--- a/perl/cgi.pl
+++ b/perl/cgi.pl
@@ -88,21 +88,8 @@ sub GN::repository { # /$username/$repository
die 'not implemented';
}
-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 {
+sub GN::cgi {
+ my ($data, $routes, $routes_cache) = @_;
my $cgi = CGI->new;
my %header = (
-Content_Type => 'text/html',
@@ -111,9 +98,12 @@ sub master {
my $method = $ENV{'REQUEST_METHOD'} || '';
my $uri = $ENV{'REQUEST_URI'} || '/';
- for my $pattern (keys %routes) {
- if ($uri =~ $route_regex_cache{$pattern}) {
- my $handler = $routes{$pattern};
+ print $cgi->header;
+ return if $method eq 'HEAD';
+
+ for my $pattern (keys %$routes) {
+ if ($uri =~ $routes_cache->{$pattern}) {
+ my $handler = $routes->{$pattern};
$handler->($uri, $1, $2, $3);
return;
}
@@ -122,6 +112,23 @@ sub master {
serve_template("404.tt", {}); # XXX missing code
}
-master() if !caller;
+sub GN::main() {
+ my $root = GIT_ROOT;
+ my %data = (
+ found => 0,
+ );
+
+ my %routes = (
+ '/' => sub { GN::index($root); },
+ '/~([\w.]+)' => sub { GN::user($root, @_) },
+ '/~([\w.]+)/([\w.]+)' => sub { GN::repository($root, @_) },
+ );
+
+ my %routes_cache = map { $_ => qr{^$_$} } keys %routes;
+
+ GN::cgi(\%data, \%routes, \%routes_cache);
+}
+
+GN::main() if !caller;
1;