J
Johnny J
I'm doing object oriented programming w/ Perl and created a Perl module
for a class. What I am trying to do within the module itself is
implement private methods or subroutines that can only be used by
(possibly public) methods within the module; I do not want them
accessible outside the module.
Here's how I'm trying to do it in the module. For flexibility, I wanted
some of my public methods to invoke the private subroutines via a hash
table to subroutine refs (which are the private subs). For what I am
trying to do, this scheme adds much flexibility and manageability, as
opposed to calling the private subroutines explicitly in the methods by
name.
-------------------------------------------------
my %PRIVMETHS = ( 'MOVE' => $prv_MOVE,
'WRITE' => $prv_WRITE,
'READ' => $prv_READ,
'DELETE' => $prv_DELETE, );
##### Private Subroutines (not access. to public) ########
my $prv_MOVE = sub {
....
}
my $prv_WRITE = sub {
....
}
my $prv_READ = sub {
....
}
my $prv_DELETE = sub {
....
}
##### Public Methods for Object Class ########
sub action {
my $self = shift;
# Method called as $obj->action(<action>, <value>), where <action> is
# any one of MOVE, WRITE, READ, DELETE, ...
...
$PRIVMETHS{$action}->($value);
...
}
-------------------------------------------------
Unfortunately, I have not been able to get this to work. I have tried
so many other convolutions to get this to work, even using evals, but no
go. Any help would be greatly appreciated!
--john
for a class. What I am trying to do within the module itself is
implement private methods or subroutines that can only be used by
(possibly public) methods within the module; I do not want them
accessible outside the module.
Here's how I'm trying to do it in the module. For flexibility, I wanted
some of my public methods to invoke the private subroutines via a hash
table to subroutine refs (which are the private subs). For what I am
trying to do, this scheme adds much flexibility and manageability, as
opposed to calling the private subroutines explicitly in the methods by
name.
-------------------------------------------------
my %PRIVMETHS = ( 'MOVE' => $prv_MOVE,
'WRITE' => $prv_WRITE,
'READ' => $prv_READ,
'DELETE' => $prv_DELETE, );
##### Private Subroutines (not access. to public) ########
my $prv_MOVE = sub {
....
}
my $prv_WRITE = sub {
....
}
my $prv_READ = sub {
....
}
my $prv_DELETE = sub {
....
}
##### Public Methods for Object Class ########
sub action {
my $self = shift;
# Method called as $obj->action(<action>, <value>), where <action> is
# any one of MOVE, WRITE, READ, DELETE, ...
...
$PRIVMETHS{$action}->($value);
...
}
-------------------------------------------------
Unfortunately, I have not been able to get this to work. I have tried
so many other convolutions to get this to work, even using evals, but no
go. Any help would be greatly appreciated!
--john