Leser: 20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!perl
package MyTest;
use Moose;
use Tk;
has 'mw' => (is => 'rw', isa => 'Any');
has 'some_val' => (is => 'rw', isa => 'Str');
my $var = '';
sub new {
my $class = shift;
my $self = bless({}, $class);
# -- init GUI
my $mw = Tk::MainWindow->new();
$self->mw($mw);
$mw->Entry(
# geht nicht, weil keine Variable:
#-textvariable => \$self->some_val,
# geht:
-textvariable => \$var,
)->pack();
$mw->Label(
-textvariable => \$var,
)->pack();
return $self;
} # /new
sub run {
my $self = shift;
$self->mw->MainLoop();
return;
} # /run
1; # /MyTest
use strict;
use warnings;
my $app = MyTest->new();
$app->run();
exit(0);
1
2
3
subtype 'TkRef' => as 'ScalarRef';
coerce 'TkRef', from 'Str', via { my $r = $_; return \$r };
has 'some_val' => (is => 'rw', isa => 'TkRef', coerce => 1);