2009-07-20 26 views
1

我发布了 "How to undersand the POE-Tk use of destroy?",试图将我的生产代码中的错误减少到测试用例。但是似乎测试用例的解决方案在整个程序中不起作用。了解POE-Tk中的名称空间

该程序长度超过800行,所以我很犹豫是否要将其完整发布。我意识到我在这里提供的代码片段可能太短而没有任何用处,但我希望能够在寻找解决方案的地方或我可以提供哪些附加信息方面获得指导。

这是我的POE-Tk应用的Session :: Create部分。


POE::Session->create(
    inline_states => { 
     _start  => \&ui_start, 
     get_zone => \&get_zone, 
     ping  => \&ping, 
     mk_disable => \&mk_disable, 
     mk_active => \&mk_active, 
     pop_up_add => \&pop_up_add, 
     add_button_press => sub { 
      my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; 
      print "\nadd button pressed\n\n"; 
      &validate; 
     }, 
     ih_button_1_press => sub { 
      my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; 
      print "\nih_button_1 pressed\n\n"; 
      if(Tk::Exists($heap->{ih_mw})) { 
       print "\n\nih_mw exists in ih_button_1_press\n\n"; 
      } else { 
       print "\n\nih_mw does not exist in ih_button_1_press\n\n"; 
      } 
      1; 
      $heap->{ih_mw}->destroy if Tk::Exists($heap->{ih_mw}); 
      &auth; 
     }, 
     pop_up_del => \&pop_up_del, 
     auth  => \&auth, 
#  validate => \&validate, 
     auth_routine => \&auth_routine, 
     raise_widget => \&raise_widget, 
     del_action => \&del_action, 
     over  => sub { exit; } 
    } 
);

add_button_press在这里被称为;


sub pop_up_add { 
    ... 
    my $add_but_2 = $add_frm_2->Button( 
     -text => "Add Record", 
     -command => $session->postback("add_button_press"), 
     -font => "{Arial} 12 {bold}") -> pack(
      -anchor => 'c', 
      -pady => 6, 
     ); 
    ... 
}

validate创建Toplevel小部件$ heap - > {ih_mw};


sub validate { 
    ... 
    if(! $valid) { 
     print "\n! valid entered\n\n"; 
     $heap->{label_text} .= "Add record anyway?"; 
     my $lt_ref = \$heap->{label_text}; 
    ... 
     my $heap->{ih_mw} = $heap->{add_mw}->Toplevel(-title => "ih_mw"); 
    ... 
     if(Tk::Exists($heap->{ih_mw})) { 
      print "\n\nih_mw exists in validate\n\n"; 
     } else { 
      print "\n\nih_mw does not exist in validate\n\n"; 
     } 
    ... 
     my $ih_but1 = $heap->{ih_mw}->Button(-text => "Add", 
      -font => 'vfont', 
      -command => $session->postback("ih_button_1_press"), 
      )->pack(-pady => 5); 
    ... 
}

按$ ih_but1结果在此;

C:\scripts\alias\resource>alias_poe_V-3_0_par.pl

添加按钮按下

称为

子验证!有效进入

ih_mw存在于验证

ih_button_1按下

ih_mwih_button_1_press

不存在这样的$heap->{ih_mw}部件似乎是未知的ih_button_1_press匿名子即使列入“($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];

+0

请尝试查看$ heap和$ heap - > {ih_mw)是否都被实际定义()。如果没有定义$ heap,那么你可能仍然会遇到与上一篇文章相同的问题。 – Inshallah 2009-07-20 20:22:28

+0

我在if(Tk :: Exists($ heap - > {ih_mw}))前加了一个if(defined($ heap))。它回来了,$堆被定义。 ih_button_1压... 堆被定义... ih_mw不存在ih_button_1_press ... – jpolache 2009-07-20 20:29:42

回答

2

$ heap在哪里&验证来自哪里?您不会将其作为参数传递。在$ &验证和$堆中可以堆$ & in_button_1_press不是一回事吗?您是否尝试过打印$堆的连续形式以查看这两个函数中的地址是否相同?

相关问题