You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by silent <si...@gmail.com> on 2007/01/11 02:56:21 UTC

答复: missing modules

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();
}