Dear POE programmers,

I am attempting to write a POE program that does two things:

1. construct and manage a POE::Component::XUL application;

2. follow a growing log file.

The idea is that the log file follower sends new lines in the log to the XUL
application, to be displayed in a TextWindow XUL widget. As far as the XUL
app is concerned - I got that figured out: it shows up in the browser
window, and the buttons (etc.) do what I mean for them to do. Likewise, the
log follower does what it's supposed to do, at least in so far as writing
changes to the log to STDOUT. What doesn't seem to work is for those same
changes to show up in the textwindow.

Now, although I am a reasonable programmer, I must admit to a bit of voodoo
programming in regards to POE - I'm reading the wiki, and trying to get my
head around things, but it's a lot to take in. I assume things going wrong
in my efforts have got something to do with the XUL app and the log follower
doing their thing in their own space, but the reference to the textwindow
that I pushed onto the HEAP when constructing the XUL app has the same
memory address (refaddr) as the one that the log follower pulls off the heap
when executing the log following callbacks, and still it's not working.

I hope you don't mind me posting some code, to clarify:

#######################################################
# snipped preambles...

POE::Session->create(
    'inline_states' => {
        '_start' => sub {
            my ( $kernel, $heap, $session ) = @_[KERNEL, HEAP, SESSION];

            # build XUL app
            POE::Component::XUL->spawn( {
                'port' => $PORT, # from @ARGV
                'root' => $ROOT, # from @ARGV
                'apps' => {
                    'Regman' => sub { # Regman = Registry Manager

                        # widget construction happens here
                        XUL::Node::Application::Regman->VERBOSE( $VERBOSE );
                        my $regman = XUL::Node::Application::Regman->_new;

                        # push logwindow onto heap
                        $heap->{'_logwindow'} = $regman->{'_logwindow'};

                        # return main window, this works, shows in firefox
                        return $regman->_main;
                    }
                },
            } );

            # the following is a blatant c&p from the wiki
            $_[HEAP]->{'wheel'} = POE::Wheel::FollowTail->new(
                'Filename'   => $LOGFILE, # from @ARGV
                'InputEvent' => 'got_line',
                'ErrorEvent' => 'got_error',
                'SeekBack'   => 1024,
            );
            $_[HEAP]->{'first'} = 0;
        },
        'got_line' => sub {
                
            # this is the same logwindow as when the xul app was constructed
            my $logwindow = $_[HEAP]->{'_logwindow'};
            if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
                
                # these messages show up when the log changes
                print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";

                # attempt to send msg to xul widget
                $logwindow->value( $_[ARG0] );

                # sure enough, the widget is modified, but not in firefox?
                # i.e. ->value() has changed, but the actual text widget
                # shows nothing?                
                print "LISTENING TO LOGWINDOW: " . $logwindow->value() .
"\n";
            }
            elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
                print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
            }
        },
        'got_error' => sub {
            my $logwindow = $_[HEAP]->{'_logwindow'};
            if ( $_[HEAP]->{'first'}++ && defined $logwindow ) {
                my $current = $logwindow->value;
                $logwindow->value( $current . "\n" . $_[ARG0] );
                print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
            }
            elsif ( $_[HEAP]->{'first'}++ && ! defined $logwindow ) {
                print "MESSAGE FROM LOGWATCHER: " . $_[ARG0] . "\n";
            }
        },
    },
);

#######################################################

Any hints as to what might be going on?

Thanks,

Rutger

Reply via email to