From 37dfc105683817d005b532273a0ded6a0de8a907 Mon Sep 17 00:00:00 2001 From: anon <anon@anon.anon> Date: Tue, 10 Dec 2024 20:39:02 +0100 Subject: [PATCH] Added 'Misc./hello.pl' --- Misc./hello.pl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Misc./hello.pl diff --git a/Misc./hello.pl b/Misc./hello.pl new file mode 100644 index 0000000..00b9cab --- /dev/null +++ b/Misc./hello.pl @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Cwd; +use Mojolicious::Lite; + +get '/' => sub { + my $c = shift; + + my $cwd = getcwd(); + my @file_list; + + opendir my $dh, $cwd or die; + @file_list = grep { -f "$cwd/$_" } readdir $dh; + closedir $dh; + + my %file_table; + foreach my $f (@file_list) { + open my $fh, '<', "$cwd/$f" or next; + my $contents = do { local $/; <$fh> }; + close $fh; + + $file_table{$f} = $contents; + } + + $c->stash( + dir => $cwd, + items => \%file_table, + ); + $c->render(template => 'listing'); +}; + +app->start; + +__DATA__ + +@@ listing.html.ep +<!DOCTYPE html> +<html> +<head><title>Welcome</title></head> +<body> + <h1>Listing of <%= $dir %></h1> + % foreach my $k (keys %{$items}) { + <div> + <h3><%= $k %></h3> + <pre style="margin-left: 20px"><!-- + --><%= $items->{$k} %> + </pre> + </div> + % } +</body> +</html>