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 => \<we are at runmode foo bar 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'; }