Re:Why Perl Didn't Win
by mrottenkolber on Sunday January 18, 2015 @06:53AM
(#8907298)
Why do you need to return 1 though? That seems pretty ridiculous.
Because that's how [require](http://p3rl.org/require) works:
> to indicate successful execution of any initialization code
Other dynamic languages have problems with "half"-loaded code. This mechanism is a defense against that.
It has uses. Sometimes you can also use it to write code that runs like a script if called in script mode (what some people are calling a modulino. If you really hate it there's a number of packages on CPAN to make it disappear.
Also new versions of Perl allow you to define a package scope and skip the '1;' Most Perl programmers don't use this yet since the benefit is very small and the cost is losing some back compatibility. Maybe in a few years it will be more common:
package MyApp::Web { ... }
Like a lot of things in Perl it has a use that might not be immediately evident. Its also possible a more elegant solution could have been found as well. Generally when I write real code I never notice it (the 1; is drowned out by docs and real code.
And here's the boiler plate for more modern perl:
You can define properties of the class using has 'property'; This will setup any accessors and also handle initializing them in the constructor that's created for you by default.