You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Eric A. Zarko" <er...@zarko.org> on 2003/02/24 02:25:54 UTC

[mp2.0] Can't locate object method "push_handlers" via package "Apache::RequestRec"

I am a little rusty (switched to telecomm ... just doing some web work on
the side now), but my script "looks" okay to me.  The archive and many
hours to trying different things do not seem to be helping.  Has anyone
seen this before, or can you see a problem with it?  TIA

System Info
===========
# uname -a
Linux localhost.localdomain 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686
i686 i386 GNU/Linux
# rpm -q mod_perl
mod_perl-1.99_05-3
# rpm -q httpd
httpd-2.0.40-8

Conf snippet
============
<Directory "/var/www/html">
# This mod_perl Output filter wraps html output in the standard template
    PerlOutputFilterHandler InfoMart::TemplateOutputFilter
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "/var/www/html/ztest">
    PerlFixupHandler InfoMart::SessionFixupHandler
</Directory>

SessionFixupHandler.pm
======================
#!/usr/bin/perl

package InfoMart::SessionFixupHandler;

use strict vars;
use warnings;

use Apache2 ();

use Apache::RequestRec ();
use Apache::RequestIO ();

use APR::Table ();

use Apache::Const -compile => 'OK';

use CGI::Cookie;
#use Apache::Session::Postgres;

sub handler {
  my $r = shift;

  my $table = $r->headers_in();
  my $cookies = parse CGI::Cookie($table->get("Cookie"));

  my $sessionID = ($cookies && $cookies->{'sessionID'} ?
    $cookies->{'sessionID'}->value : undef);

#TODO: validate the sessionID.  set $sessionID to undef if invalid

  if (!defined($sessionID)) {
    $r->handler('modperl');
    $r->push_handlers(PerlResponseHandler => sub {set_cookie});
  } else {
    $r->notes->set(sessionID => "$sessionID");
#    my %session;
#    tie %session, Apache::Session::Postgres, $sessionID, {
#      DataSource => 'dbi:Pg:dbname=sessions',
#      Commit     => 1
#    };
#$session{"foo"}="bar";
#    $r->notes->set('session' => \%session);
  }

  return Apache::OK;
}

sub set_cookie {
  my $r = shift;

#  my %session;
#  tie %session, Apache::Session::Postgres, undef, {
#    DataSource => 'dbi:Pg:dbname=sessions',
#    Commit     => 1
#  };
  my $sessionID = 'foo';
#  my $sessionID = $session{_session_id};
  my $cookie = CGI::cookie(-name=>"sessionID",
                           -value=>$sessionID,
                           -expires=>"+1h",
                           -path=>"/",
                           -domain=>"www.miabusinc.com",
                          );
  $r->err_headers_out->add('Set-Cookie' => $cookie);
  $r->headers_out->set(Location => "http://www.miabusinc.com/cgi-bin/cookie_check.cgi?src=".($r->uri));
  $r->status(302);
  $r->send_http_header;

  return Apache::OK;
}

1;


Error
=====
[Sun Feb 23 21:26:07 2003] [error] [client 12.236.181.139] Can't locate
object method "push_handlers" via package "Apache::RequestRec" at
/usr/lib/perl5/site_perl/5.8.0/InfoMart/SessionFixupHandler.pm line 33.


Re: [mp2.0] Can't locate object method "push_handlers" via package "Apache::RequestRec"

Posted by Stas Bekman <st...@stason.org>.
Eric A. Zarko wrote:
> I am a little rusty (switched to telecomm ... just doing some web work on
> the side now), but my script "looks" okay to me.  The archive and many
> hours to trying different things do not seem to be helping.  Has anyone
> seen this before, or can you see a problem with it?  TIA
[...]
> [Sun Feb 23 21:26:07 2003] [error] [client 12.236.181.139] Can't locate
> object method "push_handlers" via package "Apache::RequestRec" at
> /usr/lib/perl5/site_perl/5.8.0/InfoMart/SessionFixupHandler.pm line 33.

You simply haven't loaded the module which contains this method. I use the 
following helper alias:

% lookup push_handlers
There is more than one class with method 'push_handlers'
try one of:
         use Apache::ServerUtil ();
         use Apache::RequestUtil ();

For more info see:
http://perl.apache.org/docs/2.0/api/ModPerl/MethodLookup.html

though you will need to build the cvs version of mod_perl to get this 
functionality.

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