-$W->{"head_css"} as CSS is now always external.
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index cf02915..6b42e82 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -46,9 +46,11 @@ BEGIN
                $file.=".pm";
                my $who=$W->{"__PACKAGE__"};
                $who||="__My::Web" if $W->{"__My::Web_init"};
-               my $aref=($W->{"packages_used"}{$who}||=[]);
-               push @$aref,$class
-                               if !{ map(($_=>1),@$aref) }->{$class};  # Prevent duplicated entries.
+               if ($who) {
+                       my $aref=($W->{"packages_used"}{$who}||=[]);
+                       push @$aref,$class
+                                       if !{ map(($_=>1),@$aref) }->{$class};  # Prevent duplicated entries.
+                       }
                CORE::require $file;
                1;      # Otherwise 'require' would already file above.
        }
@@ -85,7 +87,6 @@ use URI::QueryParam;
 #our $W;
                # $W->{"title"}
                # $W->{"head"}
-               # $W->{"head_css"}
                # $W->{"force_charset"}
                # $W->{"heading_done"}
                # $W->{"footer_passed"}
@@ -120,7 +121,8 @@ my($class,%args)=@_;
        do { $W->{$_}=1  if !defined $W->{$_}; } for ("footer_ids");
        do { $W->{$_}=1  if !defined $W->{$_}; } for ("indexme");
        do { $W->{$_}="" if !defined $W->{$_}; } for ("head");
-       do { $W->{$_}="" if !defined $W->{$_}; } for ("head_css");
+       do { $W->{$_}="" if !defined $W->{$_}; } for ("body_attr");
+       do { $W->{$_}="en-US" if !defined $W->{$_}; } for ("language");
 
        my $footer_any=0;
        for (qw(footer_mailme footer_ids)) {
@@ -289,6 +291,7 @@ sub fatal (;$)
 my($msg)=@_;
 
        $msg="UNKNOWN" if !$msg;
+       cluck "FATAL: $msg";
 
        $W->{"indexme"}=0;      # For the case no heading was sent yet.
        $W->{"heading_done"}=0; # for the case of already sent {"header_only"}==1
@@ -427,11 +430,15 @@ my($url,%args)=@_;
        $url=top_dir($url,%args) if $url=~m#^/# || $args{"abs"};
 
        my $uri=URI->new($url);
-       for my $key (keys(%{$W->{"args_persistent"}})) {
-               my $val=$W->{"args"}{$key};
-               next if !defined $val;
-               $uri->query_param_append($key=>$val);
-               }
+       # Prefer the $uri values over "args_persistent" values.
+       $uri->query_form_hash({
+                       map({
+                               my $key=$_;
+                               my $val=$W->{"args"}{$key};
+                               (!defined $val ? () : ($key=>$val));
+                               } keys(%{$W->{"args_persistent"}})),
+                       %{$uri->query_form_hash()},
+                       });
        $url="".$uri;
 
        return $url;
@@ -695,6 +702,7 @@ my($class)=@_;
        my $client_charset=$W->{"force_charset"} || "us-ascii";
        header("Content-Style-Type"=>"text/css");
        header("Content-Script-Type"=>"text/javascript");
+       do { header("Content-Language"=>$_) if $_; } for $W->{"language"};
        $class->no_cache() if $W->{"no_cache"};
 
        while (my($key,$val)=each(%{$W->{"headers"}})) {
@@ -714,40 +722,18 @@ my($class)=@_;
                Wprint '<?xml version="1.0" encoding="'.$client_charset.'"?>'."\n";
                }
        Wprint '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
-       Wprint '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">'."\n";
+       Wprint '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'
+                       .($W->{"language"}||"en-US").'">'."\n";
        my $title=$W->{"title_prefix"}.join("",map({ ': '.$_; } ($W->{"title"} || ())));
        $title=~s#<[^>]*>##g;
        Wprint "<head>";
        Wprint "<title>$title</title>\n";
-
        if ($W->{"have_css"}) {
-               Wprint <<'HERE';
-<style type="text/css"><!--
-.cvs-id   { font-family: monospace; }
-.error    { color: red;   background-color: transparent; }
-.quote    { font-family: monospace; }
-.nowrap   { white-space: nowrap; }
-.centered { text-align: center; }
-.tab-bold { font-weight: bold; }
-.tab-head { font-weight: bold; }
-/*
-.tab-head { font-weight: bold; color: yellow; background-color: transparent; }
-body {
-               background-color: black;
-               color: white;
-               }
-:link    { color: aqua;   background-color: transparent; }
-:visited { color: teal;   background-color: transparent; }
-h1,h2    { color: yellow; background-color: transparent; }
-*/
-td       { padding: 2px; }
-caption  { caption-side: bottom; }
-.footer img { vertical-align: middle; }
+               # Everything can get overriden later.
+               Wprint <<"HERE";
+<link rel="stylesheet" type="text/css" href="@{[ url_out("/My/Web.css") ]}" />
 HERE
-               Wprint $W->{"head_css"}."\n";
-               Wprint "--></style>\n";
                }
-
        Wprint '<meta name="robots" content="'.($W->{"indexme"} ? "" : "no" ).'index,follow" />'."\n";
        Wprint $W->{"head"};
        for my $type (qw(prev next index contents start up)) {
@@ -756,7 +742,7 @@ HERE
        Wprint "</head><body";
 #      Wprint ' bgcolor="black" text="white" link="aqua" vlink="teal"'
 #                      if $W->{"browser"}->netscape() && (!$W->{"browser"}->major() || $W->{"browser"}->major()<=4);
-       do { &{$_}($W) if $_; } for $W->{"body_attr_sub"};
+       Wprint $W->{"body_attr"};
        Wprint ">\n";
 
        do { &{$_}() if $_; } for ($W->{"heading"});