cleaned up some debug prints
[urisagit/Stem.git] / Cookbook / World2.pm
CommitLineData
4536f655 1package World2;
2
3# This is class level cell with no constructor or alias registration.
4# It has two command message handlers, one to get the name and one to set it.
5
6my $name = 'UNKNOWN' ;
7
8sub hello_cmd {
9
10 return "Hello world from $name\n";
11}
12
13sub name_cmd {
14
15 my ( $self, $msg ) = @_ ;
16
17 my $data = $msg->data() ;
18
19 return unless $data ;
20
21 $name = ${$data} ;
22
23 return ;
24}
25
26
27=head1 Stem Cookbook - World2
28
29=head1 NAME
30
31World2 - A minimal class level B<Stem> cell with read/write data.
32
33=head1 DESCRIPTION
34
35This B<Stem> class level cell is an extension of the World1 class. It
36still has a method named C<world_cmd> that will return the stored
37name. The C<name_cmd> method takes a message and set the $name to its
38data.
39
40=head2 COMMAND METHOD
41
42The following code snippet in the F<World2> class
43cell is the method that will receive a hello command from a
44remote sender.
45
46 package World2;
47
48 sub hello_cmd {
49
50 return "Hello world!\n";
51 }
52
53B<Stem> makes the creation of Command message handling methods very
54I<easy>. Any return with defined data will automatically be sent back
55to the sender of this command in a response type message. In the
56method above we return the "Hello world!\n" string which will get printed on
57the console.
58
59For more information on how a message is routed to its destination
60cell in B<Stem> please see the F<Stem Messaging Design Notes>.
61
62=head1 THE CONFIGURATION FILE
63
64The following B<Stem> configuration file is used to bring a
65World2 class level cell into existance in the B<Stem> environment.
66
67[
68 class => 'Stem::Console',
69],
70[
71 class => 'World2',
72]
73
74The first entry is C<Stem::Console>, class level cell allows a user to
75manually send command messages into the B<Stem> system. It is not
76required for this module, but it is used in this example to send
77messages to the World2 class and to print responses from it. The
78second entry loads the C<World2> class. We can now refer to this class
79cell as I<World2> when we want to send it a message.
80
81=head1 USAGE
82
83Execute C<run_stem world> from the command line to run this configuration.
84You will be greeted with the B<StemE<gt>> prompt. It is now
85possible to send a message manually to I<World2>. Type the following
86command at the B<Stem> prompt:
87
88B<World2 hello>
89
90This is standard B<Stem> Console syntax, the cell address followed by
91the command name. This will send a message world_cmd method in the
92C<World2> class cell. That method returns a value, which is converted
93into a response message addressed to Stem::Console (the originator of
94the command message), and its data will be printed on the console terminal.
95
96B<"Hello world!">
97
98=head1 SEE ALSO
99
100F<Stem Cookbook Part 2>
101
102F<Stem Cookbook Part 3>
103
104=cut
105
1061;