note
Mugatu
<blockquote><em>they are essentially protected by virtue of the fact that you have to use the object</em></blockquote>
<p>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:</p>
<h3>Module</h3>
<code>
package Example::Module;
use strict;
sub new { bless {}, shift }
sub foo {
my ($s, $v1, $v2) = @_;
print "Hi '$v1' and '$v2'\n";
}
1;
</code>
<h3>Script</h3>
<code>
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");
</code>
439989
439999