我发布了 "How to undersand the POE-Tk use of destroy?",试图将生产代码中的错误减少到测试用例。但似乎测试用例的解决方案并不适用于整个程序。
该节目长达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_mw
中不存在 ih_button_1_press
即使包含“$heap->{ih_mw}
”
ih_button_1_press
匿名子程序似乎也不知道($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
小部件
答案 0 :(得分:2)
&heap; validate中的$ heap来自哪里?您不将其作为参数传递。 $ heap in& validate和$ heap in& in_button_1_press可能不是一回事吗?您是否尝试打印$ heap的字符串形式以查看两个函数中的地址是否相同?