Curses-UI-POE
view release on metacpan or search on metacpan
323334353637383940414243444546474849505152
my
$caller
=
caller
;
no
strict
"refs"
;
*{
$caller
.
"::MainLoop"
} = \
&MainLoop
;
eval
"package $caller; use POE;"
;
}
# XXX We assume that there will never be two Curses::UI::POE sessions.
my
@modal_objects
;
my
@modal_callbacks
;
# The session needed to make curses run in POE.
sub
new {
my
(
$type
,
%options
) =
@_
;
my
$self
=
&Curses::UI::new
(
@_
);
# my $self = bless Curses::UI->new, $type;
# my $self = bless &Curses::UI::new(@_), $type;
# I have to do this here, because if our first order of business is a
# dialog then the _start event will be too late. This self reference is
113114115116117118119120121122123124125126127128129130131132133sub
_clear_modal_callback {
my
(
$self
) =
@_
;
my
$top
=
pop
@modal_objects
;
# Reset focus
$top
->{-focus} = 0;
# Dispatch callback.
my
$args
=
pop
@modal_callbacks
;
my
$sub
=
shift
@$args
;
&{
$sub
}(
@$args
);
}
sub
keyin {
my
(
$self
,
$kernel
) =
@_
[ OBJECT, KERNEL ];
until
((
my
$key
=
$self
->get_key(0)) eq -1) {
$self
->feedkey(
$key
);
196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
# definition and redefine it later.
sub
Curses::UI::Widget::modalfocus () {
my
(
$this
) =
@_
;
# "Fake" focus for this object.
$this
->{-has_modal_focus} = 1;
$this
->focus;
$this
->draw;
push
@modal_objects
,
$this
;
push
@modal_callbacks
,
undef
;
# This is reentrant into the POE::Kernel
while
(
$this
->{-has_modal_focus} ) {
$poe_kernel
->loop_do_timeslice;
}
$this
->{-focus} = 0;
pop
@modal_callbacks
;
pop
@modal_objects
;
return
$this
;
}
POE::Kernel->run;
# Replace previously defined method into the symbol table.
*{
"Curses::UI::Widget::modalfocus"
} =
$modalfocus
;
}
241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
# Force the read timeout to be 0, so Curses::UI polls.
$this
->{-read_timeout} = 0;
return
$this
;
}
{
no
warnings
"redefine"
;
# None of this work's if POE isn't running...
# Redefine the callbackmodalfocus to ensure that callbacks and objects make
# it on to our own private stack.
sub
Curses::UI::Widget::callbackmodalfocus {
my
(
$this
,
$cb
) =
@_
;
# "Fake" focus for this object.
$this
->{-has_modal_focus} = 1;
$this
->focus;
$this
->draw;
push
@modal_objects
,
$this
;
if
(
defined
$cb
) {
# They need a callback, so register it.
push
@modal_callbacks
,
$cb
;
}
else
{
# Push a null callback.
push
@modal_callbacks
, [
sub
{ }];
}
# We assume our callers are going to return immediately back to the
# main event loop, so we don't need a recursive call.
return
;
}
}
=head1 NAME
( run in 0.219 second using v1.01-cache-2.11-cpan-454fe037f31 )