B
Bennett Haselton
I'm trying to figure out, if I have a LWP::UserAgent object and a
HTTP::Request object, how I can use the user-agent to request the
request object and print out a list of HTTP redirects that it
encounters along the way.
But, that's actually not the question. What I want to know is: How do
more experienced Perl programmers find the answers to these questions
when they need to get something done? I keep encountering problems
like this, reading the documentation, hitting a dead end, and having
to post in a forum or ask a friend. It's hard to believe that real
Perl programmers would have to do this for every simple question like
this, or nothing would ever get done.
Suppose you're an experienced Perl programmer but you don't know the
answer to this particular question. I look first in the documentation
page UserAgent.html. I see it says "The difference from request() is
that simple_request() will not try to handle redirects or
authentication responses. The request() method will in fact invoke
this method for each simple request it sends.", so I know about the
difference between those two.
The next thing that stands out is:
"$ua->redirect_ok( $request )
This method is called by request() before it tries to follow a
redirection to the request in $request. This should return a TRUE
value if this redirection is permissible."
It's not clear whether LWP::UserAgent calls this for *every* redirect,
or just the first one. (Taken literally, the documentation says it
will only do it for the first one -- "before it tries to follow a
redirection to the request in $request".) But still, that would mean
I'd have to create a subclass of LWP::UserAgent to override behavior
of this function. I'm hoping there's something easier.
So that's where I give up and ask someone. What would you do? Is
there something in the documentation that would make it obvious to you
what to try next? What do I need to train myself to look for?
HTTP::Request object, how I can use the user-agent to request the
request object and print out a list of HTTP redirects that it
encounters along the way.
But, that's actually not the question. What I want to know is: How do
more experienced Perl programmers find the answers to these questions
when they need to get something done? I keep encountering problems
like this, reading the documentation, hitting a dead end, and having
to post in a forum or ask a friend. It's hard to believe that real
Perl programmers would have to do this for every simple question like
this, or nothing would ever get done.
Suppose you're an experienced Perl programmer but you don't know the
answer to this particular question. I look first in the documentation
page UserAgent.html. I see it says "The difference from request() is
that simple_request() will not try to handle redirects or
authentication responses. The request() method will in fact invoke
this method for each simple request it sends.", so I know about the
difference between those two.
The next thing that stands out is:
"$ua->redirect_ok( $request )
This method is called by request() before it tries to follow a
redirection to the request in $request. This should return a TRUE
value if this redirection is permissible."
It's not clear whether LWP::UserAgent calls this for *every* redirect,
or just the first one. (Taken literally, the documentation says it
will only do it for the first one -- "before it tries to follow a
redirection to the request in $request".) But still, that would mean
I'd have to create a subclass of LWP::UserAgent to override behavior
of this function. I'm hoping there's something easier.
So that's where I give up and ask someone. What would you do? Is
there something in the documentation that would make it obvious to you
what to try next? What do I need to train myself to look for?