package My::Class::_Implementation;
sub _add
{
my $me= shift @_;
# ...
}
sub _init
{
my $me= shift @_;
# ...
}
*My::Class::instancePackage= sub {
my $class= shift @_;
return $class . "::Object";
};
*My::Class::new= sub {
my $us= shift @_;
my $me= bless {}, $us->instancePackage();
_init( $me );
return $me;
};
*My::Class::Object::new= sub {
my $me= shift @_;
my $new= bless {}, ref($me);
_init( $me );
return $me;
};
*My::Class::Object::method= sub {
my $me= shift @_;
_add( $me, @_ );
};
If you don't like the "*My::Class::..." part, then you can instead export your methods to My::Class and/or My::Class::Object depending on whether they are class methods or object methods. Lots of ways to do that.
This technique prevents using a class method on an object, prevents using an object method on the class, makes it easy for you to use your private subroutines, makes it very clear that they are private, but doesn't prevent someone from getting their job done when they realize that your class design doesn't allow for them to do their job portably so they need to implement a hack that does something with your private subs that will likely break in some future version of your module (while not having to modify your module which might be being used portably elsewhere).
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|