NAME

WWW::CurlOO::Simple - simplifies WWW::CurlOO::Easy interface

SYNOPSIS

use WWW::CurlOO::Simple;

WWW::CurlOO::Simple->new->get( $uri, \&finished );

sub finished
{
    my ( $curl, $result ) = @_;
    print "document body: $curl->{body}\n";

    # reuse connection to get another file
    $curl->get( '/other_file', \&finished2 );
}

sub finished2 { }

DESCRIPTION

WWW::CurlOO::Simple is a thin layer over WWW::CurlOO::Easy. It simplifies many common tasks, while providing access to full power of WWW::CurlOO::Easy when its needed.

WWW::CurlOO excells in asynchronous operations, thanks to a great design of libcurl(3). To take advantage of that power WWW::CurlOO::Simple interface uses callbacks even in synchronous mode, this should allow to quickly switch to async when the time comes. Of course there is nothing to stop you to use WWW::CurlOO::Simple::Async from the beginning.

CONSTRUCTOR

new( [PERMANENT_OPTIONS] )

Creates new WWW::CurlOO::Simple object.

my $curl = WWW::CurlOO::Simple->new( timeout => 60 );

METHODS

setopt( NAME, VALUE, [TEMPORARY] )

Set some option. Either permanently or only for next request if TEMPORARY is true.

setopts( PERMANENT_OPTIONS )

Set multiple options, permanently.

setopts_temp( TEMPORARY_OPTIONS )

Set multiple options, only for next request.

getinfo( NAME )

Get connection information.

my $value = $curl->getinfo( 'effective_url' );
getinfos( INFO_NAMES )

Get multiple getinfo values.

my ( $v1, $v2 ) ) $curl->getinfos( 'name1', 'name2' );
ua

Get parent WWW::CurlOO::Simple::UserAgent object.

get( URI, [TEMPORARY_OPTIONS], CALLBACK )

Issue a GET request. CALLBACK will be called upon finishing with two arguments: WWW::CurlOO::Simple object and the result value. If URI is incomplete, full uri will be constructed using $curl->{referer} as base. WWW::CurlOO::Simple updates $curl->{referer} after every request. TEMPORARY_OPTIONS will be set for this request only.

$curl->get( "http://full.uri/", sub {
    my $curl = shift;
    my $result = shift;
    die "get() failed: $result\n" unless $result == 0;

    $curl->get( "/partial/uri", sub {} );
} );
head( URI, [TEMPORARY_OPTIONS], CALLBACK )

Issue a HEAD request. Otherwise it is exactly the same as get().

post( URI, POST, [TEMPORARY_OPTIONS], CALLBACK )

Issue a POST request. POST value can be either a scalar, in which case it will be sent literally, a HASHREF - will be uri-encoded, or a WWW::CurlOO::Form object (WWW::CurlOO::Simple::Form is OK as well).

 $curl->post( $uri,
     { username => "foo", password => "bar" },
	 \&finished
 );
put( URI, PUTDATA, [TEMPORARY_OPTIONS], CALLBACK )

Issue a PUT request. PUTDATA value can be either a file name, in which case the file contents will be uploaded, a SCALARREF -- refered data will be uploaded, or a CODEREF -- sub will be called like a CURLOPT_READFUNCTION from WWW::CurlOO::Easy, you should specify "infilesize" option in the last case.

 $curl1->put( $uri, "filename", \&finished );
 $curl2->put( $uri, \"some data", \&finished );
 $curl3->put( $uri, sub {
         my ( $curl, $maxsize, $uservar ) = @_;
		 read STDIN, my ( $r ), $maxsize;
		 return \$r;
     },
     infilesize => EXPECTED_SIZE,
	 \&finished
 );

OPTIONS

Options can be either CURLOPT_* values (import them from WWW::CurlOO::Easy), or literal names, preferably in lower case, without the CURLOPT_ preffix. For description of available options see curl_easy_setopt(3).

Names for getinfo can also be either CURLINFO_* values or literal names without CURLINFO_ preffix.

SEE ALSO

WWW::CurlOO::Simple::UserAgent WWW::CurlOO::Simple::Async WWW::CurlOO::Easy

COPYRIGHT

Copyright (c) 2011 Przemyslaw Iskra <sparky at pld-linux.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.