test for symbol table/package lookup bug
[urisagit/Stem.git] / bin / cli
1 #!/usr/local/bin/perl -w
2
3 use strict ;
4
5 use IO::Socket ;
6 use Data::Dumper ;
7
8 use Stem::Packet ;
9
10 $| = 1 ;
11
12 my $host = 'localhost' ;
13
14 my $port = shift || 8888 ;
15
16 my $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' ) ;
20 my $packet = Stem::Packet->new() ;
21
22 print "type 'help' for help\n\n" ;
23
24 while( 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 }