Fixed package dependencies (missing the web request main package).
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index 5c02334..2b08495 100644 (file)
--- a/Web.pm
+++ b/Web.pm
@@ -24,7 +24,7 @@ use strict;
 use warnings;
 
 use Exporter;
-sub Wrequire($);
+sub Wrequire($%);
 sub Wuse($@);
 our $W;
 our @EXPORT=qw(
@@ -49,9 +49,10 @@ BEGIN
        use Carp qw(cluck confess);
        $W->{"__My::Web_init"}=1;
 
-       sub Wrequire ($)
+       # $args{"first"}=1
+       sub Wrequire ($%)
        {
-       my($file)=@_;
+       my($file,%args)=@_;
 
 #              print STDERR "Wrequire $file\n";
                $file=~s#/#::#g;
@@ -70,7 +71,12 @@ BEGIN
                                next if $packages_used_hash{$caller}{$target}++;
                                cluck "Appending to the '_done' package list: caller=$caller,target=$target"
                                                if $packages_used_hash{$caller}{"_done"};
-                               push @{$packages_used_array{$caller}},$target;
+                               if ($args{"first"}) {
+                                       unshift @{$packages_used_array{$caller}},$target;
+                                       }
+                               else {
+                                       push @{$packages_used_array{$caller}},$target;
+                                       }
                                }
                        }
                eval { CORE::require "$file"; } or confess $@;
@@ -163,6 +169,8 @@ my($class,%args)=@_;
        # $Apache2::Registry::curstash is no longer supported.
        do { cluck "No $_" if !$W->{$_}; } for "__PACKAGE__";
        exit_hook_start();
+       # Package dependencies tracking only:
+       Wrequire $W->{"__PACKAGE__"},"first"=>1;
 
        do { $W->{$_}=0  if !defined $W->{$_}; } for "detect_ent";
        do { $W->{$_}=0  if !defined $W->{$_}; } for "detect_js";
@@ -221,8 +229,10 @@ my($class,%args)=@_;
                        $$_=0 if !defined $$_;
                        }
                }
+       # Used only if: $W->{"http_safe"}
+       # but we would cause on different method(): Appending to the '_done' package list
+       Wrequire 'My::Hash::RecordKeys';
        if ($W->{"http_safe"}) {
-               Wrequire 'My::Hash::RecordKeys';
                $W->{"headers_in_RecordKeys"}=My::Hash::RecordKeys->new($W->{"headers_in"});
                $W->{"headers_in"}=$W->{"headers_in_RecordKeys"};
                }
@@ -276,9 +286,11 @@ my($class,%args)=@_;
                $W->{"head"}.='<script type="application/javascript" src="'.uri_escaped(path_web('/My/HaveJS.pm')).'"></script>'."\n";
                }
 
-       do { _args_check(%$_) if $_; } for ($W->{"args_check"});
-
+       # Required by &_args_check below.
        $W->{"_init_done"}=1;
+
+       do { _args_check(%$_) if $_; } for $W->{"args_check"};
+
        return $W;
 }
 
@@ -647,6 +659,7 @@ my($msg)=@_;
        if (!$W->{"heading_done"}) {
                $W->{"indexme"}=0;      # For the case no heading was sent yet.
                $W->{"header_only"}=0;  # assurance for &heading
+               $W->{"content_type"}="text/html";       # Force HTML and avoid strictly checked XHTML.
                My::Web->heading();
                }
        Wprint "\n".vskip("3ex")."<hr /><h1 class=\"error\">FATAL ERROR: $msg!</h1>\n"
@@ -1113,14 +1126,16 @@ my($f)=@_;
 
 sub cache_start()
 {
+       # Used only if: !$W->{"http_safe"}
+       # but we would cause on different method(): Appending to the '_done' package list
+       # &Wrequire it here even if it will not be later used; to be stable!
+       Wrequire 'My::Hash::RestrictTo';
        if (!$W->{"http_safe"}) {
                __PACKAGE__->_no_cache();
                return;
                }
 
        {
-               # &Wrequire it here even if it will not be later used; to be stable!
-               Wrequire 'My::Hash::RestrictTo';
                my %uri_args_hash=(
                        "method"=>$W->{"r"}->method(),
                        "uri"=>"http://".$W->{"web_hostname"}."/".$W->{"r"}->uri(),