in reply to Unlimited chaining (is there a way to detect this?)

I hate this style of code too. I blame SOAP::Lite for it, but I think it was actually imported from another language. How can you prevent it? Don't return an object instance from methods that are not intended to create objects!
  • Comment on Re: Unlimited chaining (is there a way to detect this?)

Replies are listed 'Best First'.
Re^2: Unlimited chaining (is there a way to detect this?)
by roman (Monk) on Jan 06, 2008 at 09:01 UTC

    I really dislike the SOAP::Lite style of chained methods constructors

    my $soap_client = SOAP::Lite->proxy($proxy) ->uri($uri) ->on_fault(sub {...}); .... my $soap_value = SOAP::Data ->name($name) ->value($value) ->type($type);

    and don't understand why is it pursued overall in the documentation at the expense of ordinary new:

    my $soap_value = SOAP::Data->new( 'name' => $name, 'value' => $value, 'type' => $type);

    But I think the SOAP::Lite style is different from the one discussed here.

    AFAIK SOAP::Lite methods are overloaded as being:

    • setters (when called on object with parameter)
    • constructors (when called on package with parameter). They even can be imported sometimes as functions.
    • getters (called without parameters)

    but only the setter variant can be chained as it modifies the current object and returns it. So there are no new objects created by chained methods.