Remove one cache to possible cure some "headers_in" instability.
[www.jankratochvil.net.git] / project / Lib.pm
index 86c900f..4fde277 100644 (file)
@@ -24,7 +24,6 @@ use strict;
 use warnings;
 
 use My::Web;
-require CGI;
 use Carp qw(cluck confess);
 
 use Exporter;
@@ -92,14 +91,14 @@ my($class,$ListItem)=@_;
                                                return "Download".$_[0];
                                                },
                                "format"=>sub ($) {
-                                               return a_href($_[0],CGI::escapeHTML(File::Basename::basename($_[0])),"size"=>2);
+                                               return a_href($_[0],escapeHTML(File::Basename::basename($_[0])),"size"=>2);
                                                }},
                {"key"=>qr(^link\b),"text"=>sub ($) {
                                                $_[0]=~s/^link-//;
                                                return $_[0];
                                                },
                                "format"=>sub ($) {
-                                               return($_[0]=~/^<a\b/ ? $_[0] : a_href($_[0],CGI::escapeHTML($_[0])));
+                                               return($_[0]=~/^<a\b/ ? $_[0] : a_href($_[0],escapeHTML($_[0])));
                                                }},
                {"key"=>qr(^cvs\b),"text"=>sub ($) {
                                                $_[0]=~s/^cvs//;
@@ -113,7 +112,7 @@ my($class,$ListItem)=@_;
                                                my $branch="";
                                                $branch=$1 if $val=~s/:(.*)//;
                                                return join("<br />\n\t\t",
-                                                               CGI::escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
+                                                               escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
                                                                                ." checkout".(!$branch ? "" : " -r $branch -kk")
                                                                                .($val!~m#/# ? "" : " -d ".File::Basename::basename($val))
                                                                                ." $val"),
@@ -128,9 +127,9 @@ my($class,$ListItem)=@_;
                {"key"=>"ownership","text"=>"Ownership"},
                {"key"=>"sponsorship","text"=>"Sponsorship"},
                {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
-                               return a_href("http://java.sun.com/",CGI::escapeHTML($_[0]))
+                               return a_href("http://java.sun.com/",escapeHTML($_[0]))
                                                if $_[0]=~/^Java\b/;
-                               return a_href("http://www.php.net/",CGI::escapeHTML($_[0]))
+                               return a_href("http://www.php.net/",escapeHTML($_[0]))
                                                if $_[0]=~/^PHP\b/;
                                return undef();
                                }},
@@ -191,13 +190,11 @@ sub project_arrayref_to_hashref($$)
 {
 my($self,$arrayref)=@_;
 
-       Wuse 'My::Hash::Sub::Readonly';
-       my $r={};
-       tie %$r,"My::Hash::Sub::Readonly",(
-                       @$arrayref,
-                       "keys_array"=>[ hashlikearray_get_keys(@$arrayref) ],
-                       );
-       return $r;
+       Wrequire 'My::Hash';
+       return My::Hash->new({
+               @$arrayref,
+               "keys_array"=>[ hashlikearray_get_keys(@$arrayref) ],
+               },"My::Hash::Sub","My::Hash::Readonly");
 }
 
 sub title ($$)
@@ -213,6 +210,7 @@ sub list($)
 {
 my($self)=@_;
 
+       # This cache is "headers_in" hits safe - only local files reading.
        our %list_cache;
        our @list_cache;
        if (!@list_cache) {
@@ -242,15 +240,11 @@ my($class,$name)=@_;
        return map(($_=>$class->name_to_hashref($_)),$class->list()) if !$name;
        cluck join(" ","Project name \"$name\" not listed in 'list_cache':",$class->list())
                        if !$class->list()->{$name};
-       # Do not cache &Wrequire to gets its $Id$ markers / usage map.
+       # Never cache anything to be stable for "headers_in" hits.
        Wrequire "project::${name}::Index";
-       our %cache;
-       if (!$cache{$name}) {
-               my $arrayref=eval('\@project::'.$name.'::Index::ListItem');
-               do { warn "Broken project/$name/Index.pm"; return undef(); } if !@$arrayref;
-               $cache{$name}=$class->project_arrayref_to_hashref($arrayref);
-               }
-       return $cache{$name};
+       my $arrayref=eval('\@project::'.$name.'::Index::ListItem');
+       do { warn "Broken project/$name/Index.pm"; return undef(); } if !@$arrayref;
+       return $class->project_arrayref_to_hashref($arrayref);
 }
 
 # $args{"ListItem"}=\%...;
@@ -318,37 +312,35 @@ sub platforms ($;$%)
 my($class,$platform_selected,%args)=@_;
 
        my $r="";
-       $r.='<table border="0" width="100%"><tr><td align="center">'."\n";
-               $r.='<table><tr>'."\n";
-                       $r.='<td>';
-                               $r.='<table border="1" style="border-collapse: collapse; border-style: solid; border-width: 1px;">'."\n";
-                                       $r.='<tr>'."\n";
-                                               $r.='<td style="padding: 5px; font-weight: bold;">'."\n";
-                                                       $r.='Projects';
-                                               $r.='</td>'."\n";
-                                       $r.='</tr>'."\n";
-                               $r.='</table>';
-                       $r.='</td>';
-                       $r.='<td>';
-                               $r.='<table border="1" style="border-collapse: collapse; border-style: solid;">'."\n";
-                                       $r.='<tr>'."\n";
-                                               my @platforms=@platforms;
-                                               while (@platforms) {
-                                                       my $platform_sym =shift @platforms;
-                                                       my $platform_name=shift @platforms;
-                                                       my $chosen=($platform_selected && $platform_selected eq $platform_sym);
-                                                       $r.='<td style="padding: 5px;">';
-                                                               $r.=a_href((!$platform_selected ? "" : "/project/").'#'.$platform_sym,$platform_name,
-                                                                               "attr"=>($chosen
-                                                                                               ? 'style="text-decoration: underline; font-weight: bold;"'
-                                                                                               : 'style="text-decoration: inherit; /* revoke underline */"'));
-                                                       $r.="</td>\n";
-                                                       }
-                                       $r.='</tr>'."\n";
-                               $r.='</table>'."\n";
-                       $r.='</td>'."\n";
-               $r.='</tr></table>'."\n";
-       $r.='</td></tr></table>'."\n";
+       $r.='<table border="0" class="margin-center"><tr>'."\n";
+               $r.='<td>';
+                       $r.='<table border="1" style="border-collapse: collapse; border-style: solid; border-width: 1px;">'."\n";
+                               $r.='<tr>'."\n";
+                                       $r.='<td style="padding: 5px; font-weight: bold;">'."\n";
+                                               $r.='Projects';
+                                       $r.='</td>'."\n";
+                               $r.='</tr>'."\n";
+                       $r.='</table>';
+               $r.='</td>';
+               $r.='<td>';
+                       $r.='<table border="1" style="border-collapse: collapse; border-style: solid;">'."\n";
+                               $r.='<tr>'."\n";
+                                       my @platforms=@platforms;
+                                       while (@platforms) {
+                                               my $platform_sym =shift @platforms;
+                                               my $platform_name=shift @platforms;
+                                               my $chosen=($platform_selected && $platform_selected eq $platform_sym);
+                                               $r.='<td style="padding: 5px;">';
+                                                       $r.=a_href((!$platform_selected ? "" : "/project/").'#'.$platform_sym,$platform_name,
+                                                                       "attr"=>($chosen
+                                                                                       ? 'style="text-decoration: underline; font-weight: bold;"'
+                                                                                       : 'style="text-decoration: inherit; /* revoke underline */"'));
+                                               $r.="</td>\n";
+                                               }
+                               $r.='</tr>'."\n";
+                       $r.='</table>'."\n";
+               $r.='</td>'."\n";
+       $r.='</tr></table>'."\n";
        if (!$args{"novskip"}) {
                $r.="<hr />\n";
                $r.=My::Web::vskip "6ex";
@@ -366,13 +358,11 @@ my($class,$name)=@_;
 
        print $class->platforms($item->{"platform"},"novskip"=>1);
 
-       $r.='<table border="0" width="100%"><tr><td align="center">'."\n";
-               $r.='<table border="1" style="border-collapse: collapse; border-style: solid;">'."\n";
-                       $r.='<tr><td style="font-size: larger;">'."\n";
-                               $r.=a_href "/project/$name/",$title;
-                       $r.='</td></tr>'."\n";
-               $r.='</table>'."\n";
-       $r.='</td></tr></table>'."\n";
+       $r.='<table border="1" style="border-collapse: collapse; border-style: solid;" class="margin-center">'."\n";
+               $r.='<tr><td style="font-size: larger;">'."\n";
+                       $r.=a_href "/project/$name/",$title;
+               $r.='</td></tr>'."\n";
+       $r.='</table>'."\n";
        $r.=vskip "1ex";
        return $r;
 }