10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

102CHAPTER 5 ■ LWP MODULES$browser->credentials('www.example.com:80','Subscribers','suehring' => 'badpassword');Now when the $browser object is used <strong>to</strong> access a URL within the www.example.com domainthat prompts for credentials, the credentials specified in the example will be sent.The credentials themselves die at the end of the browser object’s life. You can s<strong>to</strong>re asmany credentials inside a browser object as you need, based on the server name and realmname for the protected resource.Mirroring a <strong>Web</strong> SiteEarlier in this chapter, I mentioned LWP::Simple’s mirror() function, as well as the lwp-mirrorprogram. Both of these work well for mirroring an entire web site. The browser object also hasa mirror() method that enables a site <strong>to</strong> be mirrored, while taking advantage of the extra powerof the object’s interface.The lwp-mirror program does an excellent job of mirroring a site in a sane, easy-<strong>to</strong>understandmanner. I recommend the lwp-mirror program for nearly all mirroringoperations. lwp-mirror is called from your shell and accepts a URL and an output file asarguments:lwp-mirror Here is an example:lwp-mirror http://www.braingia.org/ local_braingia_index.htmlThe mirror() method on the browser object has two requirements as well: the URL andthe output file. Here is an example of using this method:$browser->mirror('http://www.braingia.org','local_braingia_index.html');Handling ProxiesProxies are sometimes required <strong>to</strong> access Internet services. The LWP includes a set of methodsfor working with proxies that enable you <strong>to</strong> set a proxy for a given pro<strong>to</strong>col or set of pro<strong>to</strong>cols.When a proxy is required on a given system, it’s not uncommon for it <strong>to</strong> be set among the differentenvironment variables in the shell. The LWP can use the shell environment variable forproxy. A call <strong>to</strong> the env_proxy() method will look for environment variables that indicate theproxy server <strong>to</strong> use, such as http_proxy, as in the following example:$browser->env_proxy();It doesn’t hurt <strong>to</strong> call this method if nothing is set for the proxy environment variable—theproxy value for the browser object will still be empty.The proxy() method accepts two arguments: the pro<strong>to</strong>col and the actual proxy <strong>to</strong> use.Here is its format:$browser->proxy(pro<strong>to</strong>col, proxy_server);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!