perlapp --add "POE::Wheel" --add "POE::Loop::Select" --add "POE::Resource::Aliases" --add "POE::Resource::Events" --add "POE::Resource::Extrefs" --add "POE::Resource::FileHandles" --add "POE::Resource::SIDs" --add "POE::Resource::Sessions" --add "POE::Resource::Signals" --add "POE::Resource::Statistics" --verbose --clean --force --lib lib --exe analyze.exe display.pl
####
{"Text":["Hi there...","How are you?","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","24","26","27","28","29"]}
####
use strict;
use warnings;
use Tk; # This MUST come before use POE...
use POE;
use POE::Component::Client::TCP;
use POE::Filter::Stream;
use POE::Wheel::FollowTail;
use Data::Dumper;
use JSON::XS;
# Setup input file (if any)...
my $infile = shift || die "Missing Input File...";
_displayData();
# Setup data processing...
my $sess = _processData($infile);
# This should simply create a dummy postback on the tail session
my $subref = $sess->postback('DontDie');
# Go...
print STDERR "STARTING to process data...\n";
POE::Kernel->run;
exit;
sub _processData{
my $ifile=shift || die "Missing input file";
POE::Session->create(
inline_states=>{
_start=>sub {
print "Session ", $_[SESSION]->ID, " has started.\n";
$_[KERNEL]->alias_set("myClient");
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
$_[HEAP]->{wheel}=POE::Wheel::FollowTail->new(
Seek=>0,
Filename=>$ifile,
InputEvent=>'display',
);
},
display => sub{
InputEvent=>$_[KERNEL]->post(Display=>data=>$_[ARG0]),
},
sendStop => sub{
print "Stopping file input\n";
my $heap = $_[HEAP];
delete $heap->{wheel};
},
},
),
}
sub _displayData{
my $hwid = shift;
my $text;
my $json=new JSON::XS;
$json=$json->ascii([1]);
POE::Session->create( inline_states => {
_start => sub {
$_[KERNEL]->alias_set("Display");
my $kernel=$_[KERNEL];
# WHY DO I HAVE TO DO THIS????
my $top = $poe_main_window || MainWindow->new();
#my $top = $poe_main_window;
# Create Stop button...
$top->Button(-text=>"Stop", -command=>sub{
&stop($kernel);
$top->update;
} )->pack(-side=>'bottom');
# Create top level Tree...
$text = $top->Scrolled('Text',
-scrollbars=>'osow')->
pack(-fill=>'both', -side=>'left',
-expand=>1);
},
data=>sub{
my $input=$_[ARG0] || return;
my $node=$json->decode($input);
my $txt = join("\n", @{$node->{Text}});
$text->insert('end', $txt);
$text->update;
},
});
}
sub stop{
my $ker = shift;
if ($ker){
print STDERR "Sending sendStop to myClient\n";
$ker->call("myClient","sendStop");
}
}