[ale] Private members in perl
Chris Fowler
cfowler at outpostsentinel.com
Sun Aug 1 19:26:57 EDT 2004
Here is one I'm having an issue with. I'm trying to reinvent the wheel
and create a Vector object;
package Vector;
use strict;
sub AUTOLOAD {
}
sub new {
my $type = shift;
my $class = ref $type || $type;
my @ARA = {};
my $ref = \@ARA;
bless $ref, $class;
return $ref;
}
sub get_num {
my $self = shift;
my @W = $self;
return $#W;
}
sub append {
my $self = shift;
push @{$self}, shift;
}
return 1;
# vi: set ts=2 sw=2: #
The append does not work.
On Sun, 2004-08-01 at 18:48, Fletch wrote:
> >>>>> "Chris" == Chris Fowler <cfowler at outpostsentinel.com> writes:
>
> Chris> I'm trying to figure a way to implement private members in
> Chris> perl objects but all the text I'm reading has me confused
>
> The followup you posted (using a closure as your instance) is one way;
> using something like Tie::SecureHash rather than a plain hashref is
> another. In general Perl relies on convention rather than enforcement
> in matters of encapsulation. You don't muck around with an object's
> insides unless you do so according to a published interface; if you
> decide to do so you do it with the knowledge that any breakage caused
> by doing so is your fault.
More information about the Ale
mailing list