KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Hello Perl community on SO. I am using Perl since a few years, but since I am following SO, I recognized that I know Perl not enough. I wrote I quite big script over the past 4 years and tried to do this in OO style. I know that Perl<6 is not really OO. So one point I don't like is that I have no data encapsulation, that means no Variables that are really private to a package ("class") (or maybe I don't know how to do it). I have something like this (only a small part of my script) package TAG; sub new () { my $classname = shift; my $self = {}; bless( $self, $classname ); $self->initialize(); return $self; } sub initialize() { my $self = shift; # Only an example, I have a long list of items in this "class" $self->{ID} = "NA"; } sub setID() { ... } sub getID() { ... } In my main script I am using it then this way: my $CurrentItem; $CurrentItem = new TAG(); $CurrentItem->getID() but $CurrentItem->{ID} = "Something"; is also working, but I would prefer, that this is not possible. Is there a way to get a better encapsulation of the data I am using in the "class", so that I am (or other users are) forced to use the get and set methods?
Tags (comma-separated)
Save Edits
Cancel