in reply to Generation of dynamically-static documents
Generate static pages "at will" (e.g., via cron job, or just when I run the command).set $offline to 1 in the script, then it will generate the runmode html file with every click on your local webserver.
the script:package Static::Link; use strict; use warnings; use vars '$type'; $type = 'cgi'; # default use overload '""' => sub { $_[0]->$type }; # '/cgi-bin/static.pl' => # http://server.example/cgi-bin/static.pl?rm=foo my $script = "/cgi-bin/static.cgi"; # 'html/' => # http://server.example/html/rm_foo.html my $htdocs = ""; sub cgi { "$script?".${$_[0]} } sub offline { my $link = ${$_[0]}; $link =~ tr/=/_/; # fit to your needs "$htdocs$link.html"; }
use strict; use warnings; use CGI; use HTML::Template::Compiled 0.43; my $offline = 1; # set to 1 if on development server my $q = CGI->new; print $q->header; my $dir = '/www/cgi-bin/static'; my $rm = $q->param("rm")||"foo"; my $htc = HTML::Template::Compiled->new( path => $dir, scalarref => \<<EOM, <h2>we are at runmode <tmpl_var .runmode></h2> <a href="<tmpl_var .rm.foo>">foo</a> <a href="<tmpl_var .rm.bar>">bar</a> EOM # optional # cache_dir => "$dir/cache", ); my $foo = "rm=foo"; my $bar = "rm=bar"; my %p = ( runmode => $rm, rm => { foo => bless(\$foo, "Static::Link"), bar => bless(\$bar, "Static::Link"), }, ); $htc->param(%p); print $htc->output; if ($offline) { # generate static page $Static::Link::type = 'offline'; my $link = $p{rm}->{$rm}; my $file = "$link"; open my $fh, ">./static/htdocs/$file" or die $!; print $fh $htc->output; # update: set to cgi again $Static::Link::type = 'cgi'; }
|
|---|