Dear monks,
I am trying to write an app that follows a changing log file and posts the results back to a XUL::Node TextBox widget. To keep things from blocking, I figured POE would be the way to follow the log. So far, everything seems to be working in that: 1) the widgets show up in firefox; 2) log changes are printed to STDOUT while the XUL app is doing its own thing. Unfortunately, posting the log changes to the text widget doesn't seem to work.
In a simple form, this is what I'm trying to do:
BEGIN {
$ENV{'DYLD_LIBRARY_PATH'} = '/Users/rvosa/CIPRES-and-deps/cipres-1
+.0.1/build/lib/perl/lib/ext/lib:' . $ENV{'DYLD_LIBRARY_PATH'};
use lib '/Users/rvosa/CIPRES-and-deps/cipres-1.0.1/build/lib/perl/
+lib';
}
use strict;
use POE qw(Component::XUL Wheel::FollowTail);
use XUL::Node;
use XUL::Node::Application;
use base 'XUL::Node::Application';
my $ROOT = '/Users/rvosa/CIPRES-and-deps/cipres-1.0.1/build/lib/per
+l/lib/xul-node/';
my $PORT = 8077;
my $LOGFILE = $ENV{'HOME'} . '/registry.log';
POE::Session->create(
'inline_states' => {
'_start' => sub {
my $kernel = $_[KERNEL];
my $heap = $_[HEAP];
my $session = $_[SESSION];
POE::Component::XUL->spawn( {
'port' => $PORT,
'root' => $ROOT,
'apps' => {
'Test' => sub {
return Window(
$heap->{'tb'} = TextBox(),
);
}
},
} );
$heap->{'wheel'} = POE::Wheel::FollowTail->new(
'Filename' => $LOGFILE,
'InputEvent' => 'got_line',
'SeekBack' => 1024,
);
$heap->{'first'} = 0;
},
'got_line' => sub {
my $heap = $_[HEAP];
my $tb = $heap->{'tb'};
my $msg = $_[ARG0];
if ( $heap->{'first'}++ && defined $tb ) {
# THIS DOESN'T WORK, NO UPDATE IN WIDGET
$tb->value( $msg );
print "POSTED TO TEXTBOX: $msg\n";
}
elsif ( $heap->{'first'}++ && ! defined $tb ) {
print "NO TEXTBOX: $msg\n";
}
},
},
);
$poe_kernel->run();
...but the end result is that I do get, at first, logging messages prefixed with "NO TEXTBOX: " printed to STDOUT, subsequently, when the XUL widgets are instantiated, messages with a "POSTED TO TEXTBOX: " posted to STDOUT, but nothing shows up in the actual textbox.
I am not very experienced with either XUL or POE, but I've been trying to grasp what's going on. The thing that has me stumped is the fact that the textbox widget both when created and when pulled off the heap in the log reading callback have the same memory address (I half and half expected a copy was made somewhere deep in the POE bowels) so I don't see why the ->value() method call doesn't do what it always does, i.e. display the argument inside the widget.
Any hints?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.