LWP::Curl - LWP methods implementation with Curl engine


LWP-Curl documentation  | view source Contained in the LWP-Curl distribution.

Index


NAME

Top

LWP::Curl - LWP methods implementation with Curl engine

VERSION

Top

Version 0.07

SYNOPSIS

Top

Use libcurl like LWP, $lwpcurl->get($url), $lwpcurl->timeout(15) don't care about Curl API and don't care about html encode

    use LWP::Curl;

    my $lwpcurl = LWP::Curl->new();
	my $content = $lwpcurl->get('http://search.cpan.org','http://www.cpan.org'); 
	#get the page http://search.cpan.org passing with referer http://www.cpan.org

Constructor

Top

new()

Creates and returns a new LWP::Curl object, hereafter referred to as the "lwpcurl".

    my $lwpcurl = LWP::Curl->new()

* timeout => sec

Set the timeout value in seconds. The default timeout value is 180 seconds, i.e. 3 minutes.

* headers => [0|1]

Show HTTP headers when return a content. The default is false '0'

* user_agent => 'agent86'

Set the user agent string. The default is 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'

* followlocation => [0|1]

If the spider receive a HTTP 301 ( Redirect ) they will follow?. The default is 1.

* auto_encode => [0|1]

Turn on/off auto encode urls, for get/post.

* maxredirs => number

Set how deep the spider will follow when receive HTTP 301 ( Redirect ). The default is 3.

* proxy => $proxyurl

Set the proxy in the constructor, $proxyurl will be like: http://myproxy.com:3128/ http://username:password@proxy.com:3128/

  libcurl respects the environment variables http_proxy, ftp_proxy,
  all_proxy etc, if any of those are set. The $lwpcurl->proxy option does
  however override any possibly set environment variables. 

Set how deep the spider will follow when receive HTTP 301 ( Redirect ). The default is 3.

METHODS

Top

$lwpcurl->get($url,$referer)

  Get content of $url, passando $referer se definido

    use LWP::Curl;
	my $referer = 'http://www.example.com';
	my $get_url = 'http://www.example.com/foo';
    my $lwpcurl = LWP::Curl->new();
	my $content = $lwpcurl->get($get_url, $referer); 
=cut

sub get { my ( $self, $url, $referer ) = @_;

    if ( !$referer ) {
        $referer = "";
    }

	$url = uri_escape($url,"[^:./]") if $self->{auto_encode};
    $self->{agent}->setopt( CURLOPT_REFERER, $referer );
    $self->{agent}->setopt( CURLOPT_URL,     $url );
    $self->{agent}->setopt( CURLOPT_HTTPGET, 1 );

    my $content = "";
    open( my $fileb, ">", \$content );
    $self->{agent}->setopt( CURLOPT_WRITEDATA, $fileb );
    $self->{retcode} = $self->{agent}->perform;

    if ( $self->{retcode} == 0 ) {
        print("\nTransfer went ok\n") if $self->{debug};
        return $content;
    } else {
        croak(  "An error happened: Host $url "
              . $self->{agent}->strerror( $self->{retcode} )
              . " ($self->{retcode})\n" );
		return undef;
    }
}

$lwpcurl->post($url,$hash_form,$referer)

  POST the $hash_form fields in $url, passing $referer if defined

    use LWP::Curl;

    my $lwpcurl = LWP::Curl->new();

	my $referer = 'http://www.examplesite.com/';
	my $post_url = 'http://www.examplesite.com/post/';

	my $hash_form = { 
		'field1' => 'value1',
		'field2' => 'value2',
	}

	my $content = $lwpcurl->post($post_url, $hash_form, $referer); 

$lwpcurl->timeout($sec)

  Set timeout, default 180

$lwpcurl->auto_encode($value)

  Turn on/off auto_encode

$lwpcurl->agent_alias($alias)

   Copy from L<WWW::Mechanize> begin here
   ____________________________________
   Sets the user agent string to the expanded version from a table of actual user strings.
   I<$alias> can be one of the following:

* Windows IE 6
* Windows Mozilla
* Mac Safari
* Mac Mozilla
* Linux Mozilla
* Linux Konqueror
   then it will be replaced with a more interesting one.  For instance,
   ____________________________________

   Copy from L<WWW::Mechanize> ends here, but the idea and the data structure is a copy too :) 

   $lwpcurl->agent_alias( 'Windows IE 6' );

	   sets your User-Agent to

		Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

$lwpcurl->proxy($proxyurl)

Set the proxy in the constructor, $proxyurl will be like: http://myproxy.com:3128/ http://username:password@proxy.com:3128/

libcurl respects the environment variables http_proxy, ftp_proxy, all_proxy etc, if any of those are set. The $lwpcurl->proxy option does however override any possibly set environment variables.

To disable proxy set $lwpcurl->proxy('');

$lwpcurl->proxy without argument, return the current proxy

AUTHOR

Top

Lindolfo Rodrigues de Oliveira Neto, <lorn at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-lwp-curl at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LWP-Curl. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc LWP::Curl




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=LWP-Curl

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/LWP-Curl

* CPAN Ratings

http://cpanratings.perl.org/d/LWP-Curl

* Search CPAN

http://search.cpan.org/dist/LWP-Curl

ACKNOWLEDGEMENTS

Top

Thanks to Breno G. Oliveira for the great tips. Thanks for the LWP and WWW::Mechanize for the inspiration.

COPYRIGHT & LICENSE

Top


LWP-Curl documentation  | view source Contained in the LWP-Curl distribution.