Re: Clone method
Gisle Aas (gisle@activestate.com)
11 Apr 2001 16:52:52 -0700
"Ilya A. Tereshchenko" <elliot@uic.nsu.ru> writes:
> It seems to me, that there is a bug in subj. Or, maybe, I understand the
> copy term little different? I wrote small test program:
>
> #!/usr/bin/perl
>
> use strict;
>
> use LWP::UserAgent;
>
> my $ua = new LWP::UserAgent;
> $ua->proxy('http', 'proxy:8000');
> my $ub = new LWP::UserAgent;
> my $uc = $ua->clone();
> print "ua: ".$ua->proxy('http', 'aa')."\n";
> print "ub: ".$ub->proxy('http', 'bb')."\n";
> print "uc: ".$uc->proxy('http', 'cc')."\n";
> print "ua: ".$ua->proxy('http', 'ee')."\n";
>
> and was surprised receiving the next result:
>
> ua: proxy:8000
> ub:
> uc: aa
> ua: cc
>
> I thought, it should returns something like
>
> ua: proxy:8000
> ub:
> uc: proxy:8000
> ua: aa
>
> ,should it?
>
> Please, explain me is there a bug what should be fixed
> or a feature what is a weight on my mind to no purpose.
It is a bug. This is a patch:
Index: lib/LWP/UserAgent.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/LWP/UserAgent.pm,v
retrieving revision 1.80
diff -u -p -r1.80 UserAgent.pm
--- lib/LWP/UserAgent.pm 2001/03/19 19:30:16 1.80
+++ lib/LWP/UserAgent.pm 2001/04/11 23:50:52
@@ -495,6 +495,7 @@ sub clone
my $copy = bless { %$self }, ref $self; # copy most fields
# elements that are references must be handled in a special way
+ $copy->{'proxy'} = { %{$self->{'proxy'}} };
$copy->{'no_proxy'} = [ @{$self->{'no_proxy'}} ]; # copy array
$copy;