问题描述:

what is this '->' thingy doing in the below context I have no clue what it means.

This is not an object we create at least not the traditional way with new nor I can imagine the '->' lines are arguments to a subroutine call.

my $Interface = SOAP::Lite

-> uri("urn:iControl:$name")

-> readable(1)

-> proxy("https://$sHost/iControl/iControlPortal.cgi");

A hint is appreciated to move on with this first time seen syntax after several years using Perl every now and then.

I am confused.

thx/Hermann

网友答案:
a
   ->b(...)
   ->c(...)
   ->d(...)

is just a more readable way to write

a->b(...)->c(...)->d(...)

And it means

( ( a->b(...) )->c(...) )->d(...)

or

my $temp1 = a->b(...);
my $temp2 = $temp1->c(...);
$temp2->d(...)

It's just a chain of methods calls, where one method returns an object that serves as the invocant for the next.

SOAP::Lite uses a common "trick" of having setters returning the object whose attribute is set, allowing

 my $obj = Class->new();
 $obj->setter1(...);
 $obj->setter2(...);
 $obj->setter3(...);

to be written as

 my $obj = Class->new()
    ->setter1(...)
    ->setter2(...)
    ->setter3(...);
相关阅读:
Top