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:
package Example::Module; use strict; sub new { bless {}, shift } sub foo { my ($s, $v1, $v2) = @_; print "Hi '$v1' and '$v2'\n"; } 1;
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");
In reply to Re^3: Writing Modules/namespace polution
by Mugatu
in thread Writing Modules/namespace polution
by thekestrel
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |