API-Eulerian
view release on metacpan or search on metacpan
lib/API/Eulerian/EDW/Parser/JSON.pm view on Meta::CPAN
my $msg;
my $key;
# Parse JSON stream
$parser->process_tokens(
# Property begin
start_property => sub
{
$key = shift;
},
# Property end
end_property => sub
{
},
# String
add_string => sub
{
my $parent = $in[ $depth ];
if( ref( $parent ) eq 'ARRAY' ) {
$parent->[ scalar( @$parent ) ] = shift;
} elsif( ref( $parent ) eq 'HASH' ) {
$parent->{ $key } = shift;
}
},
# Number
add_number => sub
{
my $parent = $in[ $depth ];
if( ref( $parent ) eq 'ARRAY' ) {
$parent->[ scalar( @$parent ) ] = shift;
} elsif( ref( $parent ) eq 'HASH' ) {
$parent->{ $key } = shift;
}
},
# Null
add_null => sub
{
my $parent = $in[ $depth ];
if( ref( $parent ) eq 'ARRAY' ) {
$parent->[ scalar( @$parent ) ] = undef;
} elsif( ref( $parent ) eq 'HASH' ) {
$parent->{ $key } = undef;
}
},
# Object begin
start_object => sub
{
$in[ ++$depth ] = {};
},
# Object end
end_object => sub
{
my $parent = $in[ $depth - 1 ] if $depth > 0;
if( ref( $parent ) eq 'ARRAY' ) {
$parent->[ scalar( @$parent ) ] = $in[ $depth ];
} elsif( ref( $parent ) eq 'HASH' ) {
$parent->{ $key } = $in[ $depth ];
}
if( $depth == 1 ) {
$msg = $in[ $depth ];
#print( Dumper( $msg ) . "\n" ); die "";
$uuid = $msg->{ uuid };
print( "UUID : $uuid\n" );
$hooks->on_headers(
$uuid, $msg->{ from }, $msg->{ to },
$msg->{ schema }
);
}
$depth--;
},
# Array begin
start_array => sub
{
$in[ ++$depth ] = [];
},
# Array end
end_array => sub
{
my $parent = $in[ $depth - 1 ] if $depth > 0;
if( ref( $parent ) eq 'ARRAY' ) {
$parent->[ scalar( @$parent ) ] = $in[ $depth ];
} elsif( ref( $parent ) eq 'HASH' ) {
$parent->{ $key } = $in[ $depth ];
}
if( $depth == 2 && $uuid ) {
$hooks->on_add( $uuid, [ $in[ $depth ] ] );
}
$depth--;
},
);
$hooks->on_status( $uuid, '', 0, 'Success', 0 );
}
#
# Endup module properly
#
1;
( run in 0.556 second using v1.01-cache-2.11-cpan-39bf76dae61 )