You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tracy12 <j_...@yahoo.com> on 2007/01/10 05:32:20 UTC

missing modules

Hi,

I have the following piece of code within  my perl module, intention is to
update the REMOTE_USER variable.

I am using apache 2.2 with mod_perl 2.0 on Fedora core 5.

 $r->connection->user($user2);

but at run time it gives the following error.

 Can't locate object method "connection" via package "Apache2::RequestRec" 

which package should I really import is it Apache2::Connection () I tried
this and it says cannot find Connection object.

How to proceed on this.
-- 
View this message in context: http://www.nabble.com/missing-modules-tf2950618.html#a8252099
Sent from the mod_perl - General mailing list archive at Nabble.com.


答复: missing modules

Posted by silent <si...@gmail.com>.
Hi,
	I made a test with your code, yes it works,
But I have other things to ask:


Script1:
package PrintIp;

#use mod_perl2 ();
use Apache2::Const qw(:common);
#use Apache2::Request ();
use Apache2::RequestRec ();

sub handler {
        my      $r= shift;
        #my     $apr= Apache2::Request->new( $r );
        my $c = $r->connection;
        $r->print($c->remote_ip());
        return Apache2::Const::OK;
}

1;
~

Script2:
package PrintIp;

#use mod_perl2 ();
use Apache2::Const qw(:common);
use Apache2::Request ();
use Apache2::RequestRec ();

sub handler {
        my      $r= shift;
        my     $apr= Apache2::Request->new( $r );
        my $c = $apr->connection;   #different
        $r->print($c->remote_ip());
        return Apache2::Const::OK;
}

1;
~

Q: why both of the two script works? And I found the remote_ip method is in
Apache2::Connection, I never 'use' it, but I can call its method,
The Apache2::Request "use" it for me ?

I guess the $apr can call connection because it is base on $r.

Mod_perl objects sometimes very confuse to me, for example: the
Apache2::Connection pod only say :$c->method, but what is $c?
I only guess it is $c = $r->connection,(or you can say research the src
code)
Is there something like a big picture show the relationship between the
mod_perl2 related objects?


Thanks!

-----邮件原件-----
发件人: Jonathan Vanasco [mailto:jvanasco@2xlp.com] 
发送时间: 2007年1月10日 14:03
收件人: Tracy12
抄送: modperl@perl.apache.org
主题: Re: missing modules

The stuff below should work , or at least give you an idea.

// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -



package PrintIp;

use mod_perl2 ();
use Apache2::Const qw(:common);
use Apache2::Request ();
use Apache2::RequestRec ();

sub handler {
	my 	$r= shift;
	my 	$apr= Apache2::Request->new( $r );
	my  $pageUser= PageUser->new( $r , $apr );
		$r->content_type('text/html');
		$r->print( $pageUser->get_ip() );
	return Apache2::Const::OK;
}

package PageUser;

use Apache2::Request ();
use Apache2::Connection ();

sub new {
	my  $proto= $_[0];
	my  $class= ref($proto) || $proto;
	my  $self= bless( {} ,  $class);
		$self->{'ApacheRequestRec'}= $_[1];
		$self->{'ApacheRequest'}= $_[2];
	return $self;
}

sub get_ip {
	my 	( $self )= @_;
	my 	$connection= $self->{'ApacheRequest'}->connection;
	return $connection->remote_ip();
}




Re: missing modules

Posted by Jonathan Vanasco <jv...@2xlp.com>.
The stuff below should work , or at least give you an idea.

// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -



package PrintIp;

use mod_perl2 ();
use Apache2::Const qw(:common);
use Apache2::Request ();
use Apache2::RequestRec ();

sub handler {
	my 	$r= shift;
	my 	$apr= Apache2::Request->new( $r );
	my  $pageUser= PageUser->new( $r , $apr );
		$r->content_type('text/html');
		$r->print( $pageUser->get_ip() );
	return Apache2::Const::OK;
}

package PageUser;

use Apache2::Request ();
use Apache2::Connection ();

sub new {
	my  $proto= $_[0];
	my  $class= ref($proto) || $proto;
	my  $self= bless( {} ,  $class);
		$self->{'ApacheRequestRec'}= $_[1];
		$self->{'ApacheRequest'}= $_[2];
	return $self;
}

sub get_ip {
	my 	( $self )= @_;
	my 	$connection= $self->{'ApacheRequest'}->connection;
	return $connection->remote_ip();
}