Fixed package dependencies (missing the web request main package).
[MyWeb.git] / Web.pm
diff --git a/Web.pm b/Web.pm
index 1a3f9e0..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(
@@ -37,6 +37,7 @@ our @EXPORT=qw(
                $W
                &input_hidden_persistents
                &escapeHTML
+               &form_method
                );
 our @ISA=qw(Tie::Handle Exporter);
 
@@ -48,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;
@@ -66,11 +68,15 @@ BEGIN
                $callers{$selfpkg}=1;
                for my $target ($class,__PACKAGE__) {
                        for my $caller (keys(%callers)) {
-                               next if $caller eq $target;
                                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 $@;
@@ -121,12 +127,16 @@ require Digest::MD5;
 require Data::Compare;
 use Data::Dumper;
 require Encode;
+use Apache2::RequestUtil;
 use Apache2::Filter;
 use Apache2::Connection;
 require MIME::Base64;
 use Apache2::ServerUtil;
 require MIME::Types;
 require MIME::Parser;
+use Apache2::RequestRec;
+use Apache2::RequestIO;
+use Apache2::Response;
 
 
 #our $W;
@@ -159,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";
@@ -217,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"};
                }
@@ -272,12 +286,24 @@ 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;
 }
 
+sub form_method($)
+{
+my($method)=@_;
+
+       return q{enctype="application/x-www-form-urlencoded" accept-charset="us-ascii utf-8"} if $method eq "post";
+       return                                             q{accept-charset="us-ascii utf-8"} if $method eq "get";
+       cluck "Undefined method: $method";
+       return ""
+}
+
 sub merge_post_args($)
 {
 my($class)=@_;
@@ -633,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"
@@ -1099,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(),