Closed vingman closed 6 years ago
Found this in the perldoc: http://perldoc.perl.org/perlobj.html#Method-Call-Variations
Indirect Object Syntax
Outside of the file handle case, use of this syntax is discouraged as it can confuse the Perl interpreter. See below for more details.
Perl supports another method invocation syntax called "indirect object" notation. This syntax is called "indirect" because the method comes before the object it is being invoked on.
This syntax can be used with any class or object method:
my $file = new File $path, $data;
save $file;
We recommend that you avoid this syntax, for several reasons.
First, it can be confusing to read. In the above example, it's not clear if save is a method provided by the File class or simply a subroutine that expects a file object as its first argument.
When used with class methods, the problem is even worse. Because Perl allows subroutine names to be written as barewords, Perl has to guess whether the bareword after the method is a class name or subroutine name. In other words, Perl can resolve the syntax as either File->new( $path, $data ) or new( File( $path, $data ) ) .
To parse this code, Perl uses a heuristic based on what package names it has seen, what subroutines exist in the current package, what barewords it has previously seen, and other input. Needless to say, heuristics can produce very surprising results!
Older documentation (and some CPAN modules) encouraged this syntax, particularly for constructors, so you may still find it in the wild. However, we encourage you to avoid using it in new code.
You can force Perl to interpret the bareword as a class name by appending "::" to it, like we saw earlier:
my $file = new File:: $path, $data;
Thanks Victoria, this is a good point. We should avoid using new XXXXX to call initiate a new class. I think perl interpret my code as new(AaronTools::Substitute(xxxxx)) here. I will try to change everything into XXXXX->new(xxxx). I have fixed these two issues, please merge into your local branch.
Ps: the updated code was push to the original/master branch.
line 759 in Geometry::substitute definition: my $sub_object = new AaronTools::Substituent( name => $sub, end => $end ); Results in error when calling bin/substitute command line tool: Undefined subroutine &AaronTools::Substituent called at /home/deo/Aaron/AaronTools/Geometry.pm line 759.
Changing line 759 to my $sub_object = AaronTools::Substituent->new( name => $sub, end => $end ); resolves this issue