| 1 | package Net::Curl::Simple::UserAgent; | ||
| 2 | |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use Net::Curl::Share qw(CURLSHOPT_SHARE /^CURL_LOCK_DATA_/); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use base qw(Net::Curl::Share); | ||
| 7 | |||
| 8 | our $VERSION = '0.13'; | ||
| 9 | |||
| 10 | my %common_options = ( | ||
| 11 | useragent => __PACKAGE__ . ' v' . $VERSION, | ||
| 12 | ); | ||
| 13 | |||
| 14 | sub setopts | ||
| 15 | { | ||
| 16 | my $share = shift; | ||
| 17 | my %opts = @_; | ||
| 18 | |||
| 19 | $share = \%common_options | ||
| 20 | unless ref $share; | ||
| 21 | |||
| 22 | @$share{ keys %opts } = values %opts; | ||
| 23 | } | ||
| 24 | *setopt = \&setopts; | ||
| 25 | |||
| 26 | sub new | ||
| 27 | { | ||
| 28 | my $class = shift; | ||
| 29 | |||
| 30 | my $share = $class->SUPER::new(); | ||
| 31 | |||
| 32 | $share->SUPER::setopt( CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE ); | ||
| 33 | $share->SUPER::setopt( CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS ); | ||
| 34 | $share->setopts( %common_options, @_ ); | ||
| 35 | |||
| 36 | return $share; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub curl | ||
| 40 | { | ||
| 41 | my $share = shift; | ||
| 42 | require Net::Curl::Simple; | ||
| 43 | return Net::Curl::Simple->new( %$share, @_, share => $share ); | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | |||
| 48 | __END__ | ||