Leser: 1
![]() |
![]() |
5 Einträge, 1 Seite |
1
2
3
4
5
6
my $dbh = DBI->connect( 'dbi:Oracle:<<DAS_HIER>>',
'user',
'pass',
) || die "Database connection not made: $DBI::errstr";
$dbh->disconnect();
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/usr/bin/perl
use warnings;
use strict;
# Tk support is enabled if the Tk module is used before POE itself.
use Tk;
use POE;
use POE qw( Component::EasyDBI );
use Data::Dumper qw/Dumper/;
use Perl6::Say;
# -- Set up the DBI
POE::Component::EasyDBI->spawn( # or new(), witch returns an obj
alias => 'EasyDBI',
dsn => 'dbi:Oracle:localhost',
username => 'username',
password => 'password',
options => {
AutoCommit => 0,
},
);
# -- Create the session that will drive the user interface.
POE::Session->create(
inline_states => {
_start => \&ui_start,
ev_count => \&ui_count,
ev_clear => \&ui_clear,
get_some_data => \&get_some_data,
dummy_result_handler => \&dummy_result_handler,
},
);
# Run the program until it is exited.
$poe_kernel->run();
exit 0;
=head2 METHODEN
=head3 ui_start( ??? )
Create the user interface when the session starts. This assumes
some familiarity with Tk. ui_start() illustrates four important
points.
1. Tk events require a main window. POE creates one for internal
use and exports it as $poe_main_window. ui_start() uses that as the
basis for its user interface.
2. Widgets we need to work with later, such as the counter display,
must be stored somewhere. The heap is a convenient place for them.
3. Tk widgets expect callbacks in the form of coderefs. The
session's postback() method provides coderefs that post events when
called. The Button created in ui_start() fires an "ev_clear" event
when it is pressed.
4. POE::Kernel methods such as yield(), post(), delay(), signal(),
and select() (among others) work the same as they would without Tk.
This feature makes it possible to write back end sessions that
support multiple GUIs with a single code base.
=cut
sub ui_start {
my ( $self, $kernel, $session, $heap ) = @_[ OBJECT, KERNEL, SESSION, HEAP ];
# ------------------------------------------------------------
# - Initialisierung
# ------------------------------------------------------
# -- Test: etwas Inhalt einfügen
# ...
# ------------------------------------------------------
$heap->{testlabel} = $poe_main_window->Label(-text => 'start')->pack();
# ------------------------------------------------------------
# - Statusbar
# -> für den UI-Counter
require Tk::StatusBar;
$heap->{statusbar} = $poe_main_window->StatusBar();
$heap->{statusbar}->addLabel(
-relief => 'flat',
-text => "Welcome to the statusbar",
);
$heap->{statusbar}->addLabel(
-text => 'Frame:',
-width => '10',
-anchor => 'center',
);
$heap->{statusbar}->addLabel(
-width => 20,
-anchor => 'center',
-textvariable => \$heap->{counter},
-foreground => 'blue',
);
$heap->{statusbar}->addLabel(
-width => 10,
-anchor => 'center',
-text => "Clear",
-foreground => 'blue',
-command => $session->postback("ev_clear"),
-event => '<Button-1>',
);
# ------------------------------------------------------------
# - Test-Zeug
testzeug( $heap, $poe_main_window );
say "yield2get_some_data";
$kernel->yield('get_some_data');
say "yield2ev_count";
$kernel->yield("ev_count");
} # /ui_start
=head3 testzeug( $heap, $poe_main_window )
Dient dazu diverses Testzeug auszuführen, z.B: Debugging.
Bei Auslieferung des Programms sollte diese Funktion nichts mehr machen, aber
dennoch enthalten sein damit man später mal schnell was debuggen kann.
=cut
sub testzeug {
my $heap = shift;
my $mw = shift;
} # /testzeug
=head2 ui_count( ??? )
Handle the "ev_count" event by increasing a counter and displaying
its new value.
=cut
sub ui_count {
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
$heap->{counter}++;
$kernel->yield("ev_count");
} # /ui_count
=head2 ui_clear
Handle the "ev_clear" event by clearing and redisplaying the
counter.
=cut
sub ui_clear {
$_[HEAP]->{counter} = 0;
} # /ui_clear
=head2 dummy_result_handler( ... )
$_[ARG0] = {
sql => The SQL you sent
result => hash ref of hash refs keyed on primary key
placeholders => The placeholders
action => 'hashhash'
cols => array of columns in order (to help recreate the sql order)
error => Error occurred, check this first
result => ... result varies ...
}
print Dumper $_[ARG0]->{sql};
=cut
sub dummy_result_handler {
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
$heap->{testlabel}->configure(-text => $_[ARG0]->{result}->{CurrentTime});
print Dumper $_[ARG0];
$kernel->delay( 'get_some_data' => 2 );
} # /dummy_result_handler
=head2 get_some_data( ... )
Fetch some data here
=cut
sub get_some_data {
my ($self, $kernel, $heap) = @_[OBJECT, KERNEL, HEAP];
#say "get_it";
$kernel->post( 'EasyDBI',
hash => {
sql => q{select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "CurrentTime" from dual},
event => 'dummy_result_handler',
}
);
} # /get_some_data
=head1 QUELLEN
http://poe.perl.org/?POE_Cookbook/Tk_Interfaces
This sample program creates a very simple Tk counter. Its interface
consists of three widgets: A rapidly increasing counter, and a
button to reset that counter.
=cut
![]() |
![]() |
5 Einträge, 1 Seite |