Let me decipher this definition for Run :
sub Run(&){ my ($decl) = @_; $decl->(); }
This means a routine called Run , which takes a parameter of type CODE (therefore uses (&) ). Inside it, $decl assigned this passed code, and this code is called $decl->(); .
Now, the last lines in your example:
Run { cmd { "echo hello world " }; expect { exit_code => 0, capture => 2}; };
equivalent to:
Run(sub { cmd { "echo hello world " }; expect { exit_code => 0, capture => 2}; });
In other words, it calls Run with an anonymous procedure code, which is in braces.
source share