#!/usr/bin/perl # gen.pl -- generate static files for perlisdead.org use strict; use warnings; use experimental 'switch'; use File::Copy; use FindBin '$Bin'; # Change directory to script path chdir $Bin; # Generate index.html mkdir 'out' if ! -d 'out'; open my $f, '<', 'src/index.html' or die "Could not open < src/index.html: $!"; open my $g, '>', 'out/index.html.tmp' or die "Could not open > out/index.html.tmp: $!"; for (<$f>) { when (/^\.inc (.*)/) { open my $h, '<', "inc/$1" or do { warn "Could not open inc/$1: $!"; next; }; print $g $_ while <$h>; close $h; } when (/^\.eval (.*)/) { no strict; no warnings; no experimental; local *STDOUT = $g; eval $1; warn $@ if $@; } when (/^\.run (.*)/) { open my $h, '<', "run/$1" or do { warn "Could not open run/$1: $!"; next; }; my $c = do { local $/; <$h> }; close $h; local *STDOUT = $g; local $0 = "run/$1"; no strict; no warnings; no experimental; eval $c; warn $@ if $@; # I guess you could just shell out instead... } default { print $g $_; } } close $g; close $f; # Copy static files opendir my $dh, 'src' or die "Could not open directory src: $!"; while (readdir $dh) { copy "src/$_" => "out/$_" unless /^\./ or /^index\.html$/; } closedir $dh; # Rename temporary file move 'out/index.html.tmp' => 'out/index.html';