Perl is syntactically flexible and often has more than one syntax. For example, calling methods. This is the regular and recommended syntax:
Foo -> new (1, 2, 3);
This is the indirect syntax:
new Foo 1, 2, 3;
This is all good and good, but what happens when we want to use the result of complex computation as an object with indirect musical notation?
# set up some constructors for demonstration purposes *Foo::new = *Bar::new = sub {say "@_"};
The solution is a passive block:
new {rand > .5 ? "Foo" : "Bar"} 1, 2, 3;
You probably already know the dative blocks from file descriptors: print {$handles[-1]} $_ .
The dative block is executed before the method is resolved, since method resolution usually (but not in your case) depends on the type of object. However, no methods are allowed if the die s block.
Indirect notation is still pretty popular for designers, since Perl looks like C ++. However, Perl (unlike C ++) does not have a new operator: this is just an ordinary method. This flexibility may have been a bad idea, so you can "fix" it using no indirect if you are determined to do so.
source share