are you doing filter->get() anywhere to do the conversion? 


----- Original Message ----
From: "Votava, Craig M (Craig)" <[EMAIL PROTECTED]>
To: POE Mailing List <poe@perl.org>
Sent: Monday, October 27, 2008 8:54:28 AM
Subject: Help with POE::Filter::JSON

Folks-



I'm trying to learn how to use POE::Filter::JSON, but am having some
problems (none of the input is being un-JSON-ified).



Attached is my code so far.



Any suggestions or pointers are much appreciated.



Thanks



-Craig



Use this as the contents of the input file (or any json input):
{"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");
    }
}

Reply via email to