Shannon Eric Peevey wrote:
Perrin Harkins wrote:

On Mon, 2003-06-09 at 13:57, Shannon Eric Peevey wrote:

To answer your original question, Apache::Peek on CPAN now works with both mod_perl versions. And while it uses separate implementations for each version, the test suite uses the same code to test both.


Yeah, I've been messing with that, but it seems to me that I need something similar to a preprocessor directive, where I can load the appropriate "use MODULE" lines into the module bases upon which version of modperl they have installed. Is it possible to use the BEGIN {} subroutine as this?


You don't need a preprocessor.  You can call require inside an if/else
conditional, unlike use() statements which run at compile time and skip
the conditional logic.

For example:

if ($mod_perl::VERSION >= 1.99) {
 require Apache2::Module;
 import Apache2::Module;
} else {
 require Apache1::Module;
 import Apache1::Module;
}

You can put that whole construct in a BEGIN block if you want to.  That
will make it run before the rest of the code in the current package.

- Perrin

Ok, I'm back... :( Here is the code, modified to use "require":

use mod_perl;

# setting the constants to help identify which version of mod_perl
# is installed
use constant MP2 => ($mod_perl::VERSION >= 1.99);

# test for the version of mod_perl, and use the appropriate libraries
# if (!MP2) { use Apache::Constants qw(:common); }
if (MP2) {
       require Apache::Const;
       import Apache::Access;
       require Apache::Access;
       import Apache::Access;
       require Apache::Connection;
       import Apache::Connection;
       require Apache::Log;
       import Apache::Log;
       require Apache::RequestRec;
       import Apache::RequestRec;
       require Apache::RequestUtil;
       import Apache::RequestUtil;
}

You don't need to import anything, since none of these modules import anything. Just require will do.


Here is the code that is coughing up the error:

102 #Look for user based on UIDAttr
103
104 my $attrs = ['dn'];
105 $mesg = $ldap->search(
106 base => $basedn,
107 scope => 'sub',
108 filter => "($uidattr=$user)",
109 attrs => $attrs
110 );
111
112 if (my $error = $mesg->code())
113 {
114 $r->note_basic_auth_failure;
115 MP2 ? $r->log_error("user $user: LDAP Connection Failed: $error",$r->uri) : $r->log_reason("us
er $user: LDAP Connection Failed: $error",$r->uri);
116 MP2 ? return Apache::Log->HTTP_UNAUTHORIZED : return Apache::Constants->HTTP_UNAUTHORIZED;

this should be:


return MP2 ? Apache::HTTP_UNAUTHORIZED : Apache::Constants::HTTP_UNAUTHORIZED;

and before the handler (at the top of your module) you need to add:

BEGIN {
    if (MP2) {
        require Apache::Const;
        Apache::Const->import(-compile => 'HTTP_UNAUTHORIZED');
    }
    else {
        require Apache::Constants;
        Apache::Constants->import('HTTP_UNAUTHORIZED');
    }
}

See:
http://search.cpan.org/src/STAS/Apache-Peek-1.01/t/response/TestApachePeek/basic.pm

117 }
118
119 unless ($mesg->count())
120 {
121 $r->note_basic_auth_failure;
122 MP2 ? $r->log_error("user $user: user entry not found for filter: $uidattr=$user",$r->uri) : $
r->log_reason("user $user: user entry not found for filter: $uidattr=$user",$r->uri);
123 MP2 ? return Apache::Log->HTTP_UNAUTHORIZED : return Apache::Constants->HTTP_UNAUTHORIZED;
124 }


And, here is the error that I am getting in the Apache2 logs, (using mod_perl 1.99_09)

[Mon Jun 09 13:45:30 2003] [error] user asdf: user entry not found for filter: uid=asdf/
[Mon Jun 09 13:45:30 2003] [error] [client 127.0.0.1] Can't locate object method "HTTP_UNAUTHORIZED" via package "Apache::Log" (perhaps you forgot to load "Apache::Log"?) at /usr/local/share/perl/5.6.1/Apache/AuthNetLDAP.pm line 123.


As you can see, it is running everything up to the HTTP_UNAUTHORIZED constant...

If you have any ideas, I would greatly appreciate it. :)

Thanks,
speeves
cws

PS. As a matter of fact, I get the same error when using "use" instead... (Possibly a screwed perl or mod_perl installation? I'm running debian woody, apache 2.0.46, perl 5.6.1, mod_perl 1.99_09.)




--


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com



Reply via email to