1 package Stem::Demo::CLI ;
7 use base 'Stem::Cell' ;
13 Name this Cell was registered with.
18 class => 'Stem::Cell',
20 This value is the attributes for the included Stem::Cell which handles
21 cloning and sequencing.
28 my( $class ) = shift ;
29 #print "ARGS [@_]\n" ;
30 my $self = Stem::Class::parse_args( $attr_spec, @_ );
31 return $self unless ref $self;
44 #print $self->SUPER::_dump( "CLI TRIGGERED\n" ) ;
60 my( $self, $msg ) = @_;
62 #print $msg->dump( 'IN' ) ;
64 $self->{data_in_msg} = $msg ;
66 my $data = $msg->data() ;
68 my $op = $data->{op} ;
70 if( my $code = $op_to_code{ $op } ) {
72 $self->$code( $data ) ;
76 $self->send_reply( "unknown CLI op '$op'" ) ;
82 my ( $self, $data ) = @_;
84 my $in_msg = delete $self->{data_in_msg} ;
86 my $reply_msg = $in_msg->reply( type => 'data', data => $data ) ;
88 #print $reply_msg->dump( 'REPLY' ) ;
90 $reply_msg->dispatch() ;
95 my( $self, $data ) = @_;
97 my $key = $data->{key} ;
98 if ( defined( $key ) ) {
100 my $value = $data->{value} ;
102 $self->{data}{$key} = $value ;
104 $self->send_reply( "set '$key' to '$value'" ) ;
107 $self->send_reply( "set is missing a key" ) ;
113 my( $self, $data ) = @_;
115 my $key = $data->{key} ;
116 if ( defined( $key ) ) {
118 my $value = $self->{data}{$key} ;
120 $self->send_reply( "'$key' was set to '$value'" ) ;
123 $self->send_reply( "get is missing a key" ) ;
132 $self->send_reply( "cleared your data" ) ;
139 my $text = join '', map "\t$_ => $self->{data}{$_}\n",
140 sort keys %{$self->{data}} ;
142 $self->send_reply( "your data is:\n$text\n" ) ;
151 These are the commands supported in Stem::Demo::CLI
159 set sets a value in the CLI session hash
160 get gets a value in the CLI session hash
161 dump returns a dump of the session hash
162 clear will empty the the session hash
163 help prints this text
167 $self->send_reply( $text ) ;