#!perl -T # mtv.pl - Merlyn Technique Viewer by epoptai # 1. Interleaves source code with description. # 2. Code listed in textarea for editing and saving. use strict; use CGI qw(:standard); use LWP::Simple qw(get getstore); use HTML::Entities; use vars qw(%code $code $init $tmp $src $oop $wtc); use HTML::TableExtract; use CGI::Carp 'fatalsToBrowser'; my@oops=qw(10 13 28 38 48 55); # columns with double code listings my$url = url(); my$dat = 'index.dat'; unless(-e $dat){$init=1} &import_names('IN'); my$merlyn = 'http://web.stonehenge.com/merlyn/WebTechniques'; if($IN::action eq 'bindex'){&indexer} if(($IN::action eq 'save as')or($IN::codename)){&savecode} unless($IN::action eq 'view'){ print header,start_html(-title=>'MTV',-bgcolor=>'white',-text=>'black'),blockquote,h1('MTV'); print< Web Techniques Perl Columns of Randal L. Schwartz. On his home page he says of these articles,
"Because I'm generally busy (or lazy), I simply ran the source files through the pod2html translator so that I could put them online here. It makes them ugly sometimes, but you'll just have to live with that for now until someone comes up with a better solution."
Datafile not detected. Build an index.~;
}
if($init!=1){
my%dex = ();
my$md = (stat($dat))[9];
open(FILE,"< $dat") or die "$!";
my@dat = Index of $c Web Techniques columns coded by epoptai~;
}
print end_html;
exit;
}
if($IN::action eq 'view'){
$src = 'col' . $IN::getdoc . '.listing.txt';
$tmp = $^T . '.tmp';
my$col = 'col' . $IN::getdoc . '.html';
$wtc = $merlyn.'/'.$col;
my$wts = $merlyn.'/'.$src;
for(@oops){ if($IN::getdoc=~$_){$oop=1}}
if($oop==1){
my$MTV=get($wtc);
print header,blockquote;
print $MTV;
print end_html;
exit(0);
}
my$res;
getstore($wtc,$tmp); # had problems doing this with get
$code = get($wts) or die "$!";
unless(-e $tmp){
print header,start_html(-title=>"Column $IN::getdoc source code listing",-bgcolor=>'white',-text=>'black'),blockquote,p("The newest columns are not available online until after they appear in print in Web Techniques magazine. Until then only the source code is published at Randal's site. Try again soon! Back to index.");
encode_entities($code);
print " /iso;
$MTV=~s/( $code{$d1}<\/tt> $d0/g;
}
elsif($c1=~/through|to/){
my@total;
while($d1 <= $d2){
push @total, $code{$d1};
$d1++
}
my$sum = join(' $d0/g;
}
elsif(!$d2){
$_=~s/$d0/ $code{$d1}<\/tt> $d0/g;
}
}
}
print header;
print @MTV;
print end_html;
exit;
sub indexer{
my$c;
my$z = $merlyn . '/index.html';
my$dexter = get($z);
my$te = new HTML::TableExtract( headers => [qw(Column Listing Description)] );
$te->parse($dexter);
open (FILE,"> index.dat") or die "$!";
foreach my $ts ($te->table_states){
foreach my $row ($ts->rows){
chomp(@$row[0]);
chomp(@$row[2]);
@$row[0]=~s/col//o;
print FILE "@$row[0]\t@$row[2]\n";
$c++
}
}
close(FILE) or die "$!";
print header,start_html(-bgcolor=>'white',-text=>'black'),blockquote,p("$c Web Techniques columns indexed! Reload");
exit
}
sub savecode{
open (FILE,"> $IN::codename") or die "$!";
print FILE $IN::codebody;
close(FILE) or die "$!";
print header,start_html(-bgcolor=>'white',-text=>'black'),blockquote,p("Code saved as $IN::codename in same dir as this script.");
exit
}
~;
printf "%s updated: %s\n", $dat, scalar localtime($md);
print qq~$code
";
print end_html;
exit(0);
}
}
open(F,"< $tmp") or die "$!";
my@col = /oi;
$MTV=~s/(
)(.*?)<\/A>(<\/H1>)/$1$3<\/a>$4As rendered by
MTV<\/a><\/b> - (index<\/a>)
.*?<\/H2>)(.*?)<\/PRE>/$1$form/iso;
my@MTV=split(/
$code{$d2}<\/tt>
', @total);
$_=~s/$d0/$sum<\/pre>