&http_moved: Fixed warn on forgotten: $W->{"charset"}
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index d2878f6..dbb9c44 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -145,8 +145,8 @@ my($class,%args)=@_;
 
        # $W={} can get somehow created very easily.
        cluck "W not empty:\n".Dumper($W) if keys(%$W);
-       $W=bless My::Hash->new({}),$class;
-       $W=My::Hash->new($W,"My::Hash::Sub","My::Hash::Push");
+       $W=My::Hash->new({},"My::Hash::Sub","My::Hash::Push");
+       bless $W,$class;
        %$W=(
                "__PACKAGE__"=>scalar(caller()),
                %WebConfig,
@@ -260,7 +260,10 @@ my($class,%args)=@_;
                };
 
        if (!defined $W->{"have_style"}) {
-               $W->{"have_style"}=(!$W->{"browser"}->netscape() || ($W->{"browser"}->major() && $W->{"browser"}->major()>4) ? 1 : 0);
+               $W->{"have_style"}=sub {
+                       # Lazy-evaluation, we may not need the "User-Agent" header at all.
+                       return our $r||=(!$W->{"browser"}->netscape() || ($W->{"browser"}->major() && $W->{"browser"}->major()>4) ? 1 : 0);
+                       };
                }
 
        $W->{"have_js"}=($W->{"args"}{"have_js"} ? 1 : 0);
@@ -513,10 +516,22 @@ my($msg)=@_;
        exit;
 }
 
+sub footer_packages_used_comments()
+{
+       my $packages_used=$packages_used_array{$W->{"__PACKAGE__"}};
+       for my $package (@$packages_used) {
+               my $cvs_id=(eval('$'.$package."::CVS_ID")
+#                              || $package     # debug
+                               );
+               Wprint '<!-- '.$package.' - $'.$cvs_id.'$ -->'."\n" if $cvs_id;
+               }
+}
+
 sub footer()
 {
        cluck 'Explicit &footer call is deprecated, !_exit_dne' if !$W->{"_exit_done"};
        exit if $W->{"footer_done"}++;  # deadlock prevention:
+       &{$_}() for reverse @{$W->{"footer_sub_push"}};
        if ($W->{"header_only"}) {
                $packages_used_hash{$W->{"__PACKAGE__"}}{"_done"}=1;
                exit;
@@ -568,12 +583,7 @@ sub footer()
                Wprint "</p>\n";
                }
 
-       for my $package (@$packages_used) {
-               my $cvs_id=(eval('$'.$package."::CVS_ID")
-#                              || $package     # debug
-                               );
-               Wprint '<!-- '.$package.' - $'.$cvs_id.'$ -->'."\n" if $cvs_id;
-               }
+       packages_used_comments();
 
        do { Wprint $_ if $_; } for $W->{"footing"};
 
@@ -696,6 +706,7 @@ my($self,$url,$status)=@_;
        $W->{"r"}->headers_out()->{"Location"}=$url;
        $W->{"header_only"}=1;
        $W->{"content_type"}=0;
+       $W->{"charset"}=0;
        My::Web->heading();
        exit;
        die "NOTREACHED";
@@ -1093,7 +1104,8 @@ my($class)=@_;
        header("Cache-Control"=>"public");      # HTTP/1.1
 
        # Use $W->{"charset"}=0 to disable charset.
-       $W->{"charset"}="us-ascii" if !defined $W->{"charset"} && !defined($W->{"content_type"}) || $W->{"content_type"};
+       $W->{"charset"}="us-ascii"
+                       if !defined $W->{"charset"} && (!defined($W->{"content_type"}) || $W->{"content_type"});
 
        # Workaround bug
        #   https://bugzilla.mozilla.org/show_bug.cgi?id=120556