I’m not too familiar with Perl, but I am using it for a simple script I am going to write. This script will interface with Qualys so while looking up information about the Qualys API I found this statement while looking through their sample code. I have put it on Pastebin.com (here) so you don’t have to download it to view it. If for some reason you do want to download it yourself, here is a link to the page where I got it for those that want to be able to download the source (it’s the “Get Map” one).
Anyways, here is the statement (line 261) that has me a little confused:
$request = new HTTP::Request GET => $url;
I’m confused about the new and GET => $url parts of the statement.
- I think I mostly understand what’s going on with the
newpart of the statement, but if someone could explain how theHTTP::Requestworks with creating a newLWP::UserAgentthat would help clarify this line (I looked at LWP::UserAgent on CPAN, but the “KEY/DEFAULT” table they have under thenewsubroutine explanation made little sense to me). - I really have no idea what is happening in the
GET => $urlpart of the statement. My guess is that it is assigning a value in eitherHTTP::RequestorLWP::UserAgentbut I can’t find any information to back up that idea.
The given line is equivalent to
which could also be written as
The example used the indirect method syntax.
The connection between
HTTP::RequestandLWP::UserAgentis sketched in the CPAN documentation as followes:So The
HTTP:.Request->new(...)creates a new request which can be executed by a user agent