Skip to content

Commit d78eba6

Browse files
committed
revise agent/_agent changes
1 parent 6f19c48 commit d78eba6

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

Changes

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ Release notes for HTTP-Tiny
22

33
{{$NEXT}}
44

5-
[ADDED]
6-
7-
- Added '_agent' method which generates the default 'agent' string
8-
9-
[NEW FEATURES]
5+
[FIXED]
106

11-
- Modifying the 'agent' attribute with the accessor will now behave more like LWP::UserAgent
7+
- Modifying the 'agent' attribute with the accessor will append the
8+
default agent string, just like setting it during construction
129

1310
0.032 2013-06-20 11:41:24 America/New_York
1411

lib/HTTP/Tiny.pm

+12-21
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,37 @@ BEGIN {
5656
@_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor};
5757
};
5858
}
59-
60-
push @attributes, 'agent';
6159
}
6260

6361
sub agent {
6462
my($self, $agent) = @_;
6563
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;
7066
}
7167
return $self->{agent};
7268
}
7369

7470
sub new {
7571
my($class, %args) = @_;
7672

77-
my $default_agent = $class->_agent;
78-
7973
my $self = {
80-
agent => $default_agent,
8174
max_redirect => 5,
8275
timeout => 60,
8376
verify_SSL => $args{verify_SSL} || $args{verify_ssl} || 0, # no verification by default
8477
no_proxy => $ENV{no_proxy},
8578
};
8679

87-
$args{agent} .= $default_agent
88-
if defined $args{agent} && $args{agent} =~ / $/;
80+
bless $self, $class;
8981

9082
$class->_validate_cookie_jar( $args{cookie_jar} ) if $args{cookie_jar};
9183

9284
for my $key ( @attributes ) {
9385
$self->{$key} = $args{$key} if exists $args{$key}
9486
}
9587

88+
$self->agent( exists $args{agent} ? $args{agent} : $class->_agent );
89+
9690
# Never override proxy argument as this breaks backwards compat.
9791
if (!exists $self->{proxy} && (my $http_proxy = $ENV{http_proxy})) {
9892
if ($http_proxy =~ m{\Ahttp://[^/?#:@]+:\d+/?\z}) {
@@ -109,16 +103,7 @@ sub new {
109103
(defined $self->{no_proxy}) ? [ split /\s*,\s*/, $self->{no_proxy} ] : [];
110104
}
111105

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;
122107
}
123108

124109
=method get|head|put|post|delete
@@ -388,6 +373,12 @@ my %DefaultPort = (
388373
https => 443,
389374
);
390375

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+
391382
sub _request {
392383
my ($self, $method, $url, $args) = @_;
393384

0 commit comments

Comments
 (0)