curl-users
Re: the perl interface
Date: Tue, 19 Dec 2000 18:29:47 +0100
Hohi,
On Tue, Dec 19, 2000 at 04:43:58PM +0100, Daniel Stenberg wrote:
> hi ho
>
> I'm one of those fools who write a lot of weird perl hacks that do quick
> downloads from various sites to mock with.
>
> So far, I haven't really messed with the perl interface to curl and I've come
> to realize that it is because I would like a better interface!
Hm, it just imitates the C interface, perhaps you should think of making
a better C-interface before complaining about the perl interface. ;-)))
But speaking seriously, the perl interface i wrote was just a hack, as i needed
it badly (calling curl as an external program was too inefficient). I've been a
C programmer for years, and have never liked object oriented programming, so my
perl interface is not very "perlish" or object oriented, but just imitates the
C interface.
Everyone may feel free to improve it...
> I would like my perl scripts that fetch a web page to look similar to:
>
> /* create a new curl entity */
> my $url = new CURL;
That's just the object oriented version of
$curl = Curl::easy::curl_easy_init();
> /* set some options */
> $url->opts('headers' => 1,
> 'mute' => 1);
And this would just be a wrapper around curl_easy_setopt() that
get's a handle from curl_easy_init() and a list of options passed in, and
that loops over the list and calls curl_easy_setopt() for each option.
> /* get web page */
> @body = $url->get('http://curl.haxx.se/');
>
> /* print the page */
> print @body;
That's really the "perlish" way to fetch a page. ;-) What about
($errcode, @headers, @body) = $url->get();
BTW: The current way in libcurl to specify a buffer where error messages may be
stored is not very elegant, imho. I think retrieving the error message with the
newly introduced function curl_easy_getinfo() would be more consistent.
But how to put the headers and the body into the arrays. The current
perl interface is still missing the feature of registering callback
functions, and i haven't had the time to implement this. We could make
an internal callback function within the perl interface, that collects
all header and body lines in two large buffers and makes these buffers
available to the calling script? This may further increase performance,
as we don't need to save the results to a file and then open and read this
file...
> ... because most of my scripts use very few options and the main focus is
> almost always to get the page into an array.
Well, i need lots of options, and particularly acces to the headers and errors.
> Would this be possible?
Nothing is impossible...
> What do you other fellows think? Is there anyone that
> uses this? Is there anyone that has looked into how the already existing perl
> modules for this work?
That makes me curious too. Anyone out there has ever used the perl interface?
Bye,
Georg
Received on 2000-12-19