From: Martin K. <mar...@fe...> - 2007-10-04 11:16:08
|
Hi there, around line 2250 in SOAP/Lite.pm, there's the package SOAP::Client. It creates a bunch of setter/getter methods, like this: *$method = sub { my $self = shift->new; @_ ? ($self->{$field} = shift, return $self) : return $self->{$field}; } I stumbled across the first line of these methods today, when writing a loopback test transport backend: It calls the transport backend's new() every time one of these methods is called, regardless of whether it's been called before.n In my opinion, this introduces two misbehaviours: a) the constructor new() is frequently called as an object method - which is a perlish, but nonetheless bad habit b) all initialization (or whatever a user has done to the transport layer between calling new() and the next method call) is lost, as there's alway a fresh method there. This means that users cannot set LWP::UserAgent's characteristica by calling $soap->transport->some_lwp_method(1);, because send_receive (at least in the HTTP transport class) might call $self->endpoint, and thus operate on a new object. Are there any reasons for SOAP::Client behaving like this ? If not, I'd change the line to my $self = ref $_[0] ? shift : shift->new(); which also guarantees there's a valid SOAP::Client object, but does not override existing ones. This might induce subtle side effects, even though there's no effect on the test suite. Any opinions ? Marti |