#!/usr/bin/perl -w
use strict;

use Curl::easy;

my $url='http://www.gulasidorna.se/main/search/hits.asp?NewFields=&StartLocation=GeographicMenu&SearchByMap=Yes&StreetName=Kungsgatan&StreetNumber=1&CityName=STOCKHOLM';

sub body_callback {
	my ($chunk,$handle)=@_;
	return length($chunk);
}

my $curl = Curl::easy::init() or die "curl init failed!\n";
$::errbuf = "";
Curl::easy::setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
Curl::easy::setopt($curl, CURLOPT_ERRORBUFFER, "::errbuf");
Curl::easy::setopt($curl, CURLOPT_WRITEFUNCTION, \&body_callback);
#Curl::easy::setopt($curl, CURLOPT_PROXY, "http://shotwire:3128/");

Curl::easy::setopt($curl, CURLOPT_URL, $url);
my @body;
Curl::easy::setopt($curl, CURLOPT_FILE, \@body);
Curl::easy::setopt($curl, CURLOPT_COOKIEJAR, "cookie.jar");

print STDERR "curling $url\n";
if (Curl::easy::perform($curl)) {
	    print STDERR "Failed :$::errbuf\n";
}

# with this line, cookie.jar is written - without it, not.
Curl::easy::cleanup($curl);

