Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 73925 invoked from network); 4 Jan 2007 22:12:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jan 2007 22:12:10 -0000 Received: (qmail 68473 invoked by uid 500); 4 Jan 2007 22:12:09 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 68267 invoked by uid 500); 4 Jan 2007 22:12:08 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 68256 invoked by uid 99); 4 Jan 2007 22:12:08 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jan 2007 14:12:08 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: local policy) Received: from [216.148.227.152] (HELO rwcrmhc12.comcast.net) (216.148.227.152) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jan 2007 14:11:56 -0800 Received: from artemis.quinlan.org (c-24-61-17-142.hsd1.ma.comcast.net[24.61.17.142]) by comcast.net (rwcrmhc12) with SMTP id <20070104221134m1200so2dee>; Thu, 4 Jan 2007 22:11:34 +0000 Subject: Problem using PerlSection and global object in conf From: Sean P Quinlan To: modperl@perl.apache.org Content-Type: multipart/alternative; boundary="=-Usa6keftlF7qVLE5b/D1" Date: Thu, 04 Jan 2007 17:13:54 -0500 Message-Id: <1167948834.6877.111.camel@artemis.quinlan.org> Mime-Version: 1.0 X-Mailer: Evolution 2.6.0 X-Virus-Checked: Checked by ClamAV on apache.org --=-Usa6keftlF7qVLE5b/D1 Content-Type: text/plain Content-Transfer-Encoding: 7bit I have an application I am in the process of upgrading to Apache/mod_perl 2. While reading the docs, I came across this section: http://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers Which I was really excited to try! My application handles user authentication and authorization, but was designed to work from many points, not just for web pages (though that is its main function). The core just underwent a major rewrite to a cleaner, inheritable OO interface that I'm very happy with. The way the new version is designed, a 'client' object will cache the user objects (relatively small, name, email, phone etc) for users previously authenticated, using a session token as a key. Reading the document above, it seemed I would be able to create a client object at startup, which could cache 'currently' authenticated users (cleanup on the configured timeout), saving a lot of database accesses. As yet I have not been able to test the usefulness of this approach however as I can't seem to get off the ground, getting tangled with errors in configuration. Here is the relevant part of the documentation I'm trying to work from: use Bird::Eagle; $Bird::Global::object = Bird::Eagle->new(); ... PerlResponseHandler $Bird::Global::object->handler And here is the relevant portions of my configuration file (located in conf.d/): $Apache2::PerlSections::Save = 1; use CAS::Apache::Auth; # The default CAS client for the admin location $CAS_admin_client = 1; $Auth_admin = CAS::Apache::Auth->new({CLIENT_ID => $CAS_admin_client}); AuthName CAS AuthType basic PerlAuthenHandler $Auth_admin->authen # PerlAuthzHandler $Auth_admin->authz require valid-user # Order deny,allow # Deny from all Which returns the following error on configtest: Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf: Unknown type 'CAS::Apache::Auth' for directive Auth_admin at /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/Apache2/PerlSections.pm line 187.\n Commenting out the PerlAuthenHandler directive in location has no effect on the error. I've spent a day searching docs and the mailing list, trying all sorts of variations, with no luck (and some annoyance, with repeated references to docs like eg/perl_sections.txt which I can't find in the distribution!). My main thought was to move the entire section under : use CAS::Apache::Auth; $CAS_admin_client = 1; $Auth_admin = CAS::Apache::Auth->new({CLIENT_ID => $CAS_admin_client}); $Location{"/Cas"} = { PerlAuthenHandler => $Auth_admin->authen, AuthName => 'CAS', AuthType => 'basic', require => 'valid-user', }; Which got me: Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf: \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n \t(in cleanup) \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n Ah! The authen method gets $self and then $r, then gets the status and password with $r->get_basic_auth_pw. Oops, I'm calling the method instead of setting it as a handler. Perhaps setting it as a coderef? So I changed PerlAuthenHandler to: PerlAuthenHandler => \$Auth_admin->authen, But I still get: Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf: \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n \t(in cleanup) \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n Is what I am trying to do actually possible? Do I have a stupid typo or such somewhere? The first error (Unknown type 'CAS::Apache::Auth' for directive Auth_admin), and other PerlSection docs seem to indicate to me that under sections, $Foo = 'bar'; is the equivalent of Foo bar (Directive value), and does not create variables usable in other parts of the conf. But I'm at a loss to understand why a code reference being set as the target handler executes the code during configuration. If in the handler I catch the call from conf and return harmlessly, will calls while running work the way I think the docs indicate? Help solving this to do what I want would be greatly appreciated! ==================================== Details, details: SuSE 10.1 (net install) 267: 4:07pm % uname -a Linux xxxxxxxx 2.6.16.27-0.6-default #1 Wed Dec 13 09:34:50 UTC 2006 i686 athlon i386 GNU/Linux 268: 3:50pm % /usr/sbin/apache2ctl -V Server version: Apache/2.2.0 Server built: Jul 27 2006 13:28:51 Server's Module Magic Number: 20051115:0 Architecture: 32-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/srv/www" -D SUEXEC_BIN="/usr/sbin/suexec2" -D DEFAULT_PIDLOG="/var/run/httpd2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="/var/run/accept.lock" -D DEFAULT_ERRORLOG="/var/log/apache2/error_log" -D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types" -D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf" 269: 4:06pm % perl -V Summary of my perl5 (revision 5 version 8 subversion 8) configuration: Platform: osname=linux, osvers=2.6.16, archname=i586-linux-thread-multi uname='linux tait 2.6.16 #1 smp tue mar 14 18:04:33 utc 2006 i686 i686 i386 gnulinux ' config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe', cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement' ccversion='', gccversion='4.1.0 (SUSE Linux)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags ='' libpth=/lib /usr/lib /usr/local/lib libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc libc=/lib/libc-2.4.so, so=so, useshrplib=true, libperl=libperl.so gnulibc_version='2.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/i586-linux-thread-multi/CORE' cccdlflags='-fPIC', lddlflags='-shared' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING MULTIPLICITY PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API Built under linux Compiled at Apr 23 2006 00:26:41 @INC: /usr/lib/perl5/5.8.8/i586-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl . -- Sean P Quinlan --=-Usa6keftlF7qVLE5b/D1 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit I have an application I am in the process of upgrading to Apache/mod_perl 2. While reading the docs, I came across this section:
http://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers

Which I was really excited to try! My application handles user authentication and authorization, but was designed to work from many points, not just for web pages (though that is its main  function). The core just underwent a major rewrite to a cleaner, inheritable OO interface that I'm very happy with. The way the new version is designed, a 'client' object will cache the user objects (relatively small, name, email, phone etc) for users previously authenticated, using a session token as a key. Reading the document above, it seemed I would be able to create a client object at startup, which could cache 'currently' authenticated users (cleanup on the configured timeout), saving a lot of database accesses. As yet I have not been able to test the usefulness of this approach however as I can't seem to get off the ground, getting tangled with errors in configuration.

Here is the relevant part of the documentation I'm trying to work from:
  <Perl>
      use Bird::Eagle;
      $Bird::Global::object = Bird::Eagle->new();
  </Perl>
  ...
  PerlResponseHandler $Bird::Global::object->handler

And here is the relevant portions of my configuration file (located in conf.d/):
<Perl>
	$Apache2::PerlSections::Save = 1;
	use CAS::Apache::Auth;
	
	# The default CAS client for the admin location
	$CAS_admin_client = 1;
	$Auth_admin = CAS::Apache::Auth->new({CLIENT_ID => $CAS_admin_client});
</Perl>

<Location /CAS>
	AuthName CAS
	AuthType basic
	PerlAuthenHandler $Auth_admin->authen
#	PerlAuthzHandler $Auth_admin->authz
	require valid-user
#	Order deny,allow
#	Deny from all
</Location>

Which returns the following error on configtest:
Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf:
Unknown type 'CAS::Apache::Auth' for directive Auth_admin at /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi/Apache2/PerlSections.pm line 187.\n

Commenting out the PerlAuthenHandler directive in location has no effect on the error. I've spent a day searching docs and the mailing list, trying all sorts of variations, with no luck (and some annoyance, with repeated references to docs like eg/perl_sections.txt which I can't find in the distribution!). My main thought was to move the entire <Location> section under <Perl>:
<Perl>
	use CAS::Apache::Auth;
	
	$CAS_admin_client = 1;
	$Auth_admin = CAS::Apache::Auth->new({CLIENT_ID => $CAS_admin_client});
	
	$Location{"/Cas"} = {
		PerlAuthenHandler => $Auth_admin->authen,
		AuthName => 'CAS',
		AuthType => 'basic',
		require => 'valid-user',
	};
</Perl>

Which got me:
Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf:
\t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n\t(in cleanup) \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n

Ah! The authen method gets $self and then $r, then gets the status and password with $r->get_basic_auth_pw. Oops, I'm calling the method instead of setting it as a handler. Perhaps setting it as a coderef? So I changed PerlAuthenHandler to:
		PerlAuthenHandler => \$Auth_admin->authen,

But I still get:
Syntax error on line 20 of /etc/apache2/conf.d/CAS.conf:
\t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n\t(in cleanup) \t(in cleanup) Can't call method "get_basic_auth_pw" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/CAS/Apache/Auth.pm line 57.\n

Is what I am trying to do actually possible? Do I have a stupid typo or such somewhere? The first error (Unknown type 'CAS::Apache::Auth' for directive Auth_admin), and other PerlSection docs seem to indicate to me that under <Perl> sections, $Foo = 'bar'; is the equivalent of Foo bar (Directive value), and does not create variables usable in other parts of the conf. But I'm at a loss to understand why a code reference being set as the target handler executes the code during configuration.

If in the handler I catch the call from conf and return harmlessly, will calls while running work the way I think the docs indicate? Help solving this to do what I want would be greatly appreciated!

====================================
Details, details:

SuSE 10.1 (net install)

267: 4:07pm % uname -a
Linux xxxxxxxx 2.6.16.27-0.6-default #1 Wed Dec 13 09:34:50 UTC 2006 i686 athlon i386 GNU/Linux

268: 3:50pm % /usr/sbin/apache2ctl -V
Server version: Apache/2.2.0
Server built:   Jul 27 2006 13:28:51
Server's Module Magic Number: 20051115:0
Architecture:   32-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/srv/www"
-D SUEXEC_BIN="/usr/sbin/suexec2"
-D DEFAULT_PIDLOG="/var/run/httpd2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="/var/run/accept.lock"
-D DEFAULT_ERRORLOG="/var/log/apache2/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf"

269: 4:06pm % perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.16, archname=i586-linux-thread-multi
    uname='linux tait 2.6.16 #1 smp tue mar 14 18:04:33 utc 2006 i686 i686 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='4.1.0 (SUSE Linux)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.4.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Apr 23 2006 00:26:41
  @INC:
    /usr/lib/perl5/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    .


--
Sean P Quinlan <sean@quinlan.org>
--=-Usa6keftlF7qVLE5b/D1--