Am trying to develop my first (maybe 1st.5) GUI in Tk. I had program working in non-object oriented mode and have been converting to object oriented (only 2.3x in size (751 lines ->1776 lines), so far; :-) ).

I seem to be running into an "oddity".

There are "handler" functions, in Tk, that can be called when events happen like keyboard or timer input.

I'm running into a "unique" problem from the object oriented structure I'm converting to. When my classes are being called from a Tk event handler, calls are not finding "base" or ancestor "methods" in handler routines. Sample error messages:

Tk::Error: Undefined subroutine &Entry_Display_In_Wins::next_rand_or_r +ecorded_file called at shown.pl line 1403. <Key> (command bound to event) at blib/lib/Tk.pm (autosplit into blib/lib/auto/Tk/Error.al) line 488 Tk::Error('MainWindow=HASH(0x667084)', 'Undefined subroutine &Entr +y_Display_In_Wins::next_rand_or_rec...', '<Key>', '(command bound to +event)') called at /usr/lib/perl5/vendor_perl/5.8/cygwin/Tk.pm line 4 +06 eval {...} called at /usr/lib/perl5/vendor_perl/5.8/cygwin/Tk.pm l +ine 406 Tk::MainLoop called at shown.pl line 1720 main::main() called at shown.pl line 1727 ---- and ---- Tk::Error: Undefined subroutine &Entry_Display_In_Wins::write_db calle +d at shown.pl line 1392. <Key> (command bound to event) at blib/lib/Tk.pm (autosplit into blib/lib/auto/Tk/Error.al) line 488 Tk::Error('MainWindow=HASH(0x667084)', 'Undefined subroutine &Entr +y_Display_In_Wins::write_db cal...', '<Key>', '(command bound to even +t)') called at /usr/lib/perl5/vendor_perl/5.8/cygwin/Tk.pm line 406 eval {...} called at /usr/lib/perl5/vendor_perl/5.8/cygwin/Tk.pm l +ine 406 Tk::MainLoop called at shown.pl line 1720 main::main() called at shown.pl line 1727
Both "write_filedb" and "next_rand_or_recorded_file" are in Base classes of the handler routines.

Relevant packages are like this

package File_Rating_DB; #pckg ONE sub write_db(){}... package Entry_Ordering; #pckg TWO our @ISA = qw(File_Rating_DB); sub next_rand_or_recorded_file() {}... package Entry_Display_In_Wins; #pckg THREE our @ISA = qw(Entry_Ordering); sub __hk_space(){ call next_rand_or_recorded_file}... sub __hk_quit(){ ...calls write_db on exit } sub handle_key($tkcontext,$dbhandle,$key_event, $key_code) {} package Timed_Display_In_Wins; #pckg FOUR our @ISA = qw(Entry_Display_In_Wins); sub _handle_timer(){}
I've disabled timer ticks for now, so only events coming in are from keyboard, but got similar error:
"Tk::Error: Undefined subroutine Timed_Display_In_Wins::write_db not found..."
when it was enabled.

As may or may not be evident, the handler routines are located in pckg's THREE and FOUR, and try to call routines in pckg's TWO and ONE.

Any special "magic" I was supposed to use to get my handling routine's "base" classes to be searched?

It is, as if is "losing" my "Base" classes as it enters into my "handler(s)" from Tk.

Focusing on the keyboard, I bind it with:

$main_win->bind('<Any-KeyPress>'=>[\&handle_key, $s,Ev('A'), Ev('K')]) +;
so the routines are called like "$main_win->handle_key($s, Ev('A'), Ev('K'))", where "$s" is the main "self" data structure/pointer.

Subroutines in the same "package" seem to be called correctly, like "handle_key->calls->hk_space, but hk_space can't find "next_rand_or_recorded" from its parent.

What am I missing? :-?
Thanks!
Linda


In reply to Missing base classes when called from Tk by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.