test for symbol table/package lookup bug
[urisagit/Stem.git] / bin / cli
CommitLineData
4536f655 1#!/usr/local/bin/perl -w
2
3use strict ;
4
5use IO::Socket ;
6use Data::Dumper ;
7
8use Stem::Packet ;
9
10$| = 1 ;
11
12my $host = 'localhost' ;
13
14my $port = shift || 8888 ;
15
16my $sock = IO::Socket::INET->new( "$host:$port" ) ;
17$sock or die "can't connect to $host:$port\n" ;
18
19#my $packet = Stem::Packet->new( codec => 'YAML' ) ;
20my $packet = Stem::Packet->new() ;
21
22print "type 'help' for help\n\n" ;
23
24while( 1 ) {
25
26 print "CLI > " ;
27
28 chomp( my $line = <> ) ;
29 next unless $line =~ /\S/ ;
30
31#my $line = "foo bar bazz" ;
32
33 my %data ;
34 @data{ qw( op key value ) } = split( ' ', $line, 3 ) ;
35
36 my $write_buf = $packet->to_packet( \%data) ;
37#print "WRITE [$$write_buf]\n" ;
38
39 syswrite( $sock, "${$write_buf}" ) ;
40
41# this should be a proper non-blocking read loop but it is fine for this
42# demo.
43
44 my $bytes_read = sysread( $sock, my $read_buf, 8192 ) ;
45 last unless defined $bytes_read and $bytes_read > 0 ;
46
47 my $result = $packet->to_data( \$read_buf ) ;
48
49# print "RESULT [$$result]\n" ;
50 print Dumper $result ;
51
52#exit ;
53}