我发布了“如何理解 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 创建顶层小部件 $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];