#!/usr/bin/perl # gen.pl -- generate static files for perlisdead.org use 5.010; use strict; use warnings; use experimental 'switch'; use File::Copy; use FindBin '$Bin'; use Getopt::Std; # Parse command-line options my %opt; $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts('d', \%opt); sub main::HELP_MESSAGE { print <', 'out/index.html.tmp' or die "Could not open > out/index.html.tmp: $!"; for (<$src>) { when (/^\.inc (.*)/) { open my $h, '<', "inc/$1" or do { warn "Could not open inc/$1: $!"; next; }; print STDERR "INCLUDE: $_\n" if $opt{d}; print $out $_ while <$h>; close $h; } when (/^\.eval (.*)/) { print STDERR "EVAL: $1\n" if $opt{d}; { no strict; no warnings; no experimental; select $out; eval $1; select STDOUT; warn $@ if $@; } } when (/^\.run (.*)/) { open my $h, '<', "run/$1" or do { warn "Could not open run/$1: $!"; next; }; print STDERR "RUN: $1\n" if $opt{d}; my $c = do { local $/; <$h> }; close $h; { no strict; no warnings; no experimental; local $0 = "run/$1"; select $out; eval $c; select STDOUT; warn $@ if $@; } # I guess you *could* just run the script in a separate process... } default { print $out $_; } } close $out; close $src; # Rename temporary file move 'out/index.html.tmp' => 'out/index.html'; # Copy modified static files opendir $src, 'src' or die "Could not open directory src: $!"; opendir $out, 'out' or die "Could not open directory src: $!"; my %src = map { ($_, (stat "src/$_")[9]||0) } grep { not /^\./ or /^index\.html$/ } readdir $src; my %out = map { ($_, (stat "out/$_")[9]||0) } grep { not /^\./ or /^index\.html$/ } readdir $out; for (keys %src) { no warnings 'uninitialized'; if ($src{$_} > $out{$_}) { print STDERR "COPY: src/$_ => out/$_\n" if $opt{d}; copy "src/$_" => "out/$_"; } } closedir $out; closedir $src; print STDERR "DONE\n" if $opt{d};