diff options
Diffstat (limited to 'gen.pl')
-rw-r--r-- | gen.pl | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -2,24 +2,36 @@ # gen.pl -- generate static files for perlisdead.org -package App::PerlIsDead; -our $VERSION = '0.1'; +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 <<HELP; +usage: $0 [-d] + -d enable debug messages +HELP +} +sub main::VERSION_MESSAGE {} + # Change directory to script path + chdir $Bin; # Generate index.html + mkdir 'out' if ! -d 'out'; open my $src, '<', 'src/index.html' or die "Could not open < src/index.html: $!"; open my $out, '>', 'out/index.html.tmp' or die "Could not open > out/index.html.tmp: $!"; @@ -59,7 +71,7 @@ for (<$src>) { select STDOUT; warn $@ if $@; } - # I guess you could just shell out instead... + # I guess you *could* just run the script in a separate process... } default { print $out $_; @@ -69,9 +81,11 @@ 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; @@ -86,15 +100,3 @@ closedir $out; closedir $src; print STDERR "DONE\n" if $opt{d}; - -# Definitions - -sub main::HELP_MESSAGE { - print <<HELP; -usage: $0 [-d] - -d enable debug messages -HELP -} -sub main::VERSION_MESSAGE { - print "App::PerlIsDead version $VERSION\n"; -} |