How to get environment variables? Sepcifically REMOTE_HOST and REMOTE_ADDR

375 views
Skip to first unread message

Gabor Szabo

unread,
Aug 16, 2013, 5:17:59 PM8/16/13
to mojol...@googlegroups.com
I am playing with Mojolicius::Lite and I need to access  REMOTE_HOST and REMOTE_ADDR.
I tried

get '/' => sub {
    my $self = shift;
    use Data::Dumper;
    warn Dumper $self->req->env;
    $self->render('index');
};

but ->env is an empty hash.

Do I need to enable something or is the information somewhere else?

Mojolicious is at 4.24 and running with morbo.

regards
   Gabor

Gabriel Vieira

unread,
Aug 16, 2013, 6:01:14 PM8/16/13
to mojol...@googlegroups.com
Try $self->tx->remote_address

http://mojolicio.us/perldoc/Mojo/Transaction/HTTP
> --
> You received this message because you are subscribed to the Google Groups
> "Mojolicious" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mojolicious...@googlegroups.com.
> To post to this group, send email to mojol...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Gabriel Vieira

John Scoles

unread,
Aug 16, 2013, 7:27:45 PM8/16/13
to mojol...@googlegroups.com
Welcom to the 'Dark Side' Gabor
 
In the long run you will find
 
Mojolicious-Plugin-RemoteAddr-0.02 
 
Much more useful as getting the 'Real' remote address can be a little clunky. 
 
 Use it myself all the time.

Cheers
John 

Date: Fri, 16 Aug 2013 14:17:59 -0700
From: sza...@gmail.com
To: mojol...@googlegroups.com
Subject: [Mojolicious] How to get environment variables? Sepcifically REMOTE_HOST and REMOTE_ADDR

Gabor Szabo

unread,
Aug 23, 2013, 3:12:16 AM8/23/13
to mojol...@googlegroups.com
Gabriel,

thanks, that worked even though it is not really documented in the POD
just in the example.

OTOH the $self->req->env; I tried was documented but did not work :(

On Sat, Aug 17, 2013 at 2:27 AM, John Scoles <byte...@hotmail.com> wrote:
> Welcom to the 'Dark Side' Gabor

Uh Oh

>
> In the long run you will find
>
> Mojolicious-Plugin-RemoteAddr-0.02

Thanks, but I need a plugin for such basic thing?
Strange.

Gabor

Sebastian Riedel

unread,
Aug 23, 2013, 8:02:41 AM8/23/13
to mojol...@googlegroups.com
> thanks, that worked even though it is not really documented in the POD
> just in the example.

Of course it is documented, everything in Mojolicious is.

> OTOH the $self->req->env; I tried was documented but did not work :(

It works exactly as documented, you're just making assumptions.

>> Mojolicious-Plugin-RemoteAddr-0.02
>
> Thanks, but I need a plugin for such basic thing?

I don't see any reason for why you would need that plugin.

--
Sebastian Riedel
http://github.com/kraih
http://twitter.com/kraih
http://mojolicio.us

John Scoles

unread,
Aug 23, 2013, 9:04:24 AM8/23/13
to mojol...@googlegroups.com

 
> Subject: Re: [Mojolicious] How to get environment variables? Sepcifically REMOTE_HOST and REMOTE_ADDR
> From: kra...@googlemail.com
> Date: Fri, 23 Aug 2013 14:02:41 +0200
> To: mojol...@googlegroups.com

>
> > thanks, that worked even though it is not really documented in the POD
> > just in the example.
>
> Of course it is documented, everything in Mojolicious is.
>
> > OTOH the $self->req->env; I tried was documented but did not work :(
>
> It works exactly as documented, you're just making assumptions.
>
> >> Mojolicious-Plugin-RemoteAddr-0.02
> >
> > Thanks, but I need a plugin for such basic thing?
>
 
You have to know Gabor. 
 
Say the above sentence in the voice of John Byner,  Richard Lewis or Fran Drescher you will understand what he is saying.
 
It is all in the emphasis:
 
Here is the classic example from Leo  Rosten
 
The problem is whether to attend a concert being given by a niece.

The same sentence is put through the following paces, depending on emphasis:

  1. I should buy two tickets for her concert?--meaning:, "After what she did to me?"
  2. I should buy two tickets for her concert?--meaning: "What, you're giving me a lesson in ethics?"
  3. I should buy two tickets for her concert?--meaning: I wouldn't go even if she were giving out free passes!
  4. I should buy two tickets for her concert?--meaning: I'm having enough trouble deciding whether it's worth one.
  5. I should buy two tickets for her concert?--She should be giving out free passes, or the hall will be empty.
  6. I should buy two tickets for her concert?--Did she buy tickets to our daughter's recital?
  7. I should buy two tickets for her concert?--You mean, they call what she does a "concert"?
 
 
Thanks, but I need a plugin for such basic thing? -- Meaning :  I do not need it.
 
Cheers :)

> I don't see any reason for why you would need that plugin.
>
> --
> Sebastian Riedel
> http://github.com/kraih
> http://twitter.com/kraih
> http://mojolicio.us
>
Reply all
Reply to author
Forward
0 new messages