Update: Earlier this week I got an email from the most excellent author David Davis (many thanks!) informing me that the program works as published! Quickly, I re-tried it on my Windows-PC, and alas, it failed. However, thinking that it may be a platform thing, I quickly tried to run it on a Unix box, and immediately got bothered by real work until just recently. It turns out that it does work just fine under a variety of Unix-en, but still blows cookies on my Windows-PC. I'm wondering now if it may be my rather eclectic mix of perl module versions on my specific PC. I'll do some more testing to see what I can find, but I'm happy to see that I really did understand how to use POE::Filter::JSON in the first place! Nice module David!

Hi Monks-

For those of you following my latest questions, you're probably getting sick of this ever evolving example. I apologize for my redundancies, but it's pretty cool experiencing my expanding knowledge, while standing on the shoulders of giants!

rcaputo how tall are you anyway? :-)

In my last query it was recommended that I try different versions of JSON modules. That led me to discover POE::Filter::JSON, which seemed like a natural for what I'm doing and a great way for me to learn more about POE filters.

Alas, my effort is in vain (so far). It seems that the JSON filter isn't un-JSON-ifying anything. Here is my latest attempt. Any pointers or hints are much appreciated!

Thanks

-Craig

Here is the data for the input file:

{"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"]}

Here is the script:

use strict; use warnings; use Tk; # This MUST come before use POE... use POE; use POE::Wheel::FollowTail; use POE::Filter::Stackable; use POE::Filter::Line; use POE::Filter::JSON; use Data::Dumper; my $infile = shift || die "Missing Input File..."; _displayData(); my $sess = _processData($infile); # This should simply create a dummy postback on the tail session my $subref = $sess->postback('DontDie'); 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 { my $filters; print "Session ", $_[SESSION]->ID, " has started.\n"; $_[KERNEL]->alias_set("myClient"); my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; # Setup filters in filter stack... $filters = POE::Filter::Stackable->new( Filters=>[ POE::Filter::Line->new(), POE::Filter::JSON->new( json_any => { allow_nonref =>1, }, ), ], ); $_[HEAP]->{wheel}=POE::Wheel::FollowTail->new( Seek=>0, Filename=>$ifile, InputEvent=>'display', Filter=> $filters, ); }, 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; POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set("Display"); my $kernel=$_[KERNEL]; 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 $node=$_[ARG0] || return; #my $txt = join("\n", @{$node->{Text}}); $text->insert('end', Dumper($node) . "\n"); $text->update; }, }); } sub stop{ my $ker = shift; if ($ker){ print STDERR "Sending sendStop to myClient\n"; $ker->call("myClient","sendStop"); } }

In reply to Help Understanding POE::Filter::JSON Usage (SonOfaGun it works!) by cmv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.