http://www.perlmonks.org?node_id=440021


in reply to Re^2: Writing Modules/namespace polution
in thread Writing Modules/namespace polution

they are essentially protected by virtue of the fact that you have to use the object

I would be careful about calling much in Perl protected. Sure, general politeness will keep most people from using the package in unintended ways, but Perl sure won't:

Module

package Example::Module; use strict; sub new { bless {}, shift } sub foo { my ($s, $v1, $v2) = @_; print "Hi '$v1' and '$v2'\n"; } 1;

Script

use strict; use Example::Module; # add a new sub to the package sub Example::Module::bar { my ($s, $v1, $v2) = @_; print "Bye '$v1' and '$v2'\n"; } my $em = Example::Module->new; $em->bar("one", "two"); # call the sub not as a method Example::Module::foo('one', 'two', 'three'); # change the existing sub *Example::Module::foo = sub { my ($s, $v1, $v2) = @_; print "Oops '$v1' and '$v2'\n"; }; $em->foo("one", "two");