N
Nataku
Got a question for all you fellow Perl programmers out there.
Sometime recently I really got into Java because of an OOP class I was
taking at the university, and I have been attempting to apply what I
have learned to a Perl project I have been working on.
Everything seems to go pretty smoothly, and perl takes relatively well
to most OO stuff - but when I get to the GUI part of the program I hit
a rather annoying roadblock that I can't really seem to find a good
solution to. Basically I am attempting to create a class that will
contain a BrowseEntry widget along with a Listbox. When the user
selects a kind of category from the BrowseEntry, the Listbox should
update with all the entries from that particular category.
My problem arises when I get to assigning the command to the
BrowseEntry widget using the browsecmd hashkey/variable. I can only
assign a package function call to it, and as such - it kind of defeats
the whole OO aspect of it, since I cant keep multiple instances of it
around. The piece of code that follows should help to illustrate my
plight.
***************
sub Populate {
my ($self, $args) = @_;
$self->SUPER:
opulate($args);
my $browseEntry = $cardLabFrame->BrowseEntry( -variable =>
\$currentSet,
-browsecmd =>
\&refreshList )->pack( -side => 'top' );
}
sub refreshList{
my $self = shift;
#This doesnt work because the $self that gets shifted in here
# is actually the browseEntry widget, and I have no way that
# I know of to reliably get back to my parent object since
# there is no THIS operator in perl.
}
****************
So hopefully with this visual aid you can see my quandry. Never mind
the fact that I havent actually added the Listbox yet ... I havent
gotten that far because of this issue I stumbled upon. I did think of
a hack to get back to the parent object, by storing a reference to the
actual $self I want within an unused hashkey inside of the BrowseEntry
widget, but that seems way to hacky for me.
So I appeal to the community at large. Can any of you think of a way
out of this without hacking the language?
Ben
Sometime recently I really got into Java because of an OOP class I was
taking at the university, and I have been attempting to apply what I
have learned to a Perl project I have been working on.
Everything seems to go pretty smoothly, and perl takes relatively well
to most OO stuff - but when I get to the GUI part of the program I hit
a rather annoying roadblock that I can't really seem to find a good
solution to. Basically I am attempting to create a class that will
contain a BrowseEntry widget along with a Listbox. When the user
selects a kind of category from the BrowseEntry, the Listbox should
update with all the entries from that particular category.
My problem arises when I get to assigning the command to the
BrowseEntry widget using the browsecmd hashkey/variable. I can only
assign a package function call to it, and as such - it kind of defeats
the whole OO aspect of it, since I cant keep multiple instances of it
around. The piece of code that follows should help to illustrate my
plight.
***************
sub Populate {
my ($self, $args) = @_;
$self->SUPER:
my $browseEntry = $cardLabFrame->BrowseEntry( -variable =>
\$currentSet,
-browsecmd =>
\&refreshList )->pack( -side => 'top' );
}
sub refreshList{
my $self = shift;
#This doesnt work because the $self that gets shifted in here
# is actually the browseEntry widget, and I have no way that
# I know of to reliably get back to my parent object since
# there is no THIS operator in perl.
}
****************
So hopefully with this visual aid you can see my quandry. Never mind
the fact that I havent actually added the Listbox yet ... I havent
gotten that far because of this issue I stumbled upon. I did think of
a hack to get back to the parent object, by storing a reference to the
actual $self I want within an unused hashkey inside of the BrowseEntry
widget, but that seems way to hacky for me.
So I appeal to the community at large. Can any of you think of a way
out of this without hacking the language?
Ben