@@ -56,43 +56,37 @@ BEGIN {
56
56
@_ > 1 ? $_ [0]-> {$accessor } = $_ [1] : $_ [0]-> {$accessor };
57
57
};
58
58
}
59
-
60
- push @attributes , ' agent' ;
61
59
}
62
60
63
61
sub agent {
64
62
my ($self , $agent ) = @_ ;
65
63
if ( @_ > 1 ){
66
- $agent .= $self -> _agent
67
- if defined $agent && $agent =~ / $ / ;
68
-
69
- $self -> {agent } = $agent ;
64
+ $self -> {agent } =
65
+ (defined $agent && $agent =~ / $ / ) ? $agent . $self -> _agent : $agent ;
70
66
}
71
67
return $self -> {agent };
72
68
}
73
69
74
70
sub new {
75
71
my ($class , %args ) = @_ ;
76
72
77
- my $default_agent = $class -> _agent;
78
-
79
73
my $self = {
80
- agent => $default_agent ,
81
74
max_redirect => 5,
82
75
timeout => 60,
83
76
verify_SSL => $args {verify_SSL } || $args {verify_ssl } || 0, # no verification by default
84
77
no_proxy => $ENV {no_proxy },
85
78
};
86
79
87
- $args {agent } .= $default_agent
88
- if defined $args {agent } && $args {agent } =~ / $ / ;
80
+ bless $self , $class ;
89
81
90
82
$class -> _validate_cookie_jar( $args {cookie_jar } ) if $args {cookie_jar };
91
83
92
84
for my $key ( @attributes ) {
93
85
$self -> {$key } = $args {$key } if exists $args {$key }
94
86
}
95
87
88
+ $self -> agent( exists $args {agent } ? $args {agent } : $class -> _agent );
89
+
96
90
# Never override proxy argument as this breaks backwards compat.
97
91
if (!exists $self -> {proxy } && (my $http_proxy = $ENV {http_proxy })) {
98
92
if ($http_proxy =~ m {\A http://[^/?#:@]+:\d +/?\z } ) {
@@ -109,16 +103,7 @@ sub new {
109
103
(defined $self -> {no_proxy }) ? [ split /\s *,\s */, $self -> {no_proxy } ] : [];
110
104
}
111
105
112
- return bless $self , $class ;
113
- }
114
-
115
- sub _agent {
116
- my $class = ref ($_ [0]) || $_ [0];
117
-
118
- (my $default_agent = $class ) =~ s { ::} { -} g ;
119
- $default_agent .= " /" . ($class -> VERSION || 0);
120
-
121
- return $default_agent ;
106
+ return $self ;
122
107
}
123
108
124
109
=method get|head|put|post|delete
@@ -388,6 +373,12 @@ my %DefaultPort = (
388
373
https => 443,
389
374
);
390
375
376
+ sub _agent {
377
+ my $class = ref ($_ [0]) || $_ [0];
378
+ (my $default_agent = $class ) =~ s { ::} { -} g ;
379
+ return $default_agent . " /" . ($class -> VERSION || 0);
380
+ }
381
+
391
382
sub _request {
392
383
my ($self , $method , $url , $args ) = @_ ;
393
384
0 commit comments