Perl5 vs WWW

Martijn Koster (m.koster@nexor.co.uk)
Mon, 23 Jan 1995 00:37:20 +0000


While it's so quiet on the list...

I've been playing a bit with Perl5's new features and libwww-perl. 

In the first place I wanted perl5 '-w' to stop complaining.  But then
I reckoned the library could be implemented as Perl5 modules, I
thought the nested data structures could make handling headers easier,
and I wondered if it could be turned object oriented as well. I wanted
to get rid of the reading of entire files into memory, and have
glanced at the structure for the CERN libwww too. So now I'm totally
confused :-)

Anyway, the result of my playing can be seen in a client that mirrors
a WWW document (with If-modified-since):

  http://web.nexor.co.uk/public/aliweb/mirror/src/w3p.pl

which uses:

  http://web.nexor.co.uk/public/aliweb/libwww-perl5/WWW/

the URL.pm, Dates.pm, and Error.pm are almost straight libwww-perl
copies, but the HTTP.pm is quite different (Roy, I have added some
comments :-). The HTML and other protocol stuff I haven't even looked at.

Basically I have turned a WWW request into an object: you create it,
customise it, and send the request. You get a response code and
headers back, en then you can get the object to read the retrieved
document either in one, or in chunks. E.g.:

    use WWW::HTTP;
    my($htrequest) = new WWW::HTTP;    

    $htrequest->setheader('User-Agent', 'w3p/0.1 libwww-perl5/0.1');
    $htrequest->setheader('From', $w3p::from);
    $htrequest->proxy('ftp', 'http://web.nexor.co.uk:8001');

    my($response) = $htrequest->request('GET', $url);

    ...

    $htrequest->response(
                         # this anonymous subroutine
                         # is repeatedly called with
                         # buffers of data.
                    sub {
                        my($buff, $n) = @_; 
                        print LNK $buff;
                        $totaln += $n;
                    }
    );

This code is purely here as an experiment, this is not a release of
any kind, and all this stuff may not even be worth the hassle.
However, I'd be interested to hear if anyone else has been doing
anything with Perl5 and libwww-perl...

-- Martijn
__________
Internet: m.koster@nexor.co.uk
X-400: C=GB; A= ; P=Nexor; O=Nexor; S=koster; I=M
X-500: c=GB@o=NEXOR Ltd@cn=Martijn Koster
WWW: http://web.nexor.co.uk/mak/mak.html