http://qs321.pair.com?node_id=818866

sman has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, I'm doing some comparing between the usage of class and module. I declare a class named Foo with a instance method called hello as the following:
1 package Foo; 2 3 __PACKAGE__->hello('test1'); 4 hello('test2'); 5 6 sub hello { 7 my ($self, $arg) = @_; 8 print "hello=". $arg. "\n"; 9 } 10 1;
And the result is like this:
arg=test1 Use of uninitialized value $arg in concatenation (.) or string at line + 8
I am a bit confused by the usage of __PACKAGE__. In terms of the result, I guess line3 is calling a object method but don't see any new() syntax. Looks like line4 is calling a regular subroutine and that's why the error happens. Am I right about this?

Under which kind of situation should we use __PACKAGE__ to create an object instead of calling its new() in the caller program?

Thank.