View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Steve Scaffidi > Stem > World1



Annotate this POD


New  5
Open  0
View/Report Bugs

Stem Cookbook - World1 ^


World1 - A minimal class level Stem cell.


This is the simplest possible Stem class level cell. It contains a single method named world_cmd. Because this method ends in _cmd it is capable of being invoked remotely via a command message and have its return value sent back as a response message to the sender, which in this example is the Stem::Console cell.


The following code snippet in the World1 class cell is the method that will receive a hello command from a remote sender.

    package World1;

    sub hello_cmd {

        return "Hello world!\n";

Stem makes the creation of Command message handling methods very easy. Any return with defined data will automatically be sent back to the sender of this command in a response type message. In the method above we return the "Hello world!\n" string which will get printed on the console.

For more information on how a message is routed to its destination cell in Stem please see the Stem Messaging Design Notes.


The following Stem configuration file is used to bring a World1 class level cell into existance in the Stem environment.

- class: Stem::Console - class: World1

The first entry is Stem::Console, a class level cell allows a user to manually send command messages into the Stem system. It is not required for this module, but it is used in this example to send messages to the World1 class and to print responses from it. The second entry loads the World1 class. We can now refer to this class cell as World1 when we want to send it a message.


Execute run_stem world from the command line to run this configuration. You will be greeted with the Stem> prompt. It is now possible to send a message manually to World1. Type the following command at the Stem prompt:

World1 hello

This is standard Stem Console syntax, the cell address followed by the command name. This will send a message world_cmd method in the World1 class cell. That method returns a value, which is converted into a response message addressed to Stem::Console (the originator of the command message), and its data will be printed on the console terminal.

"Hello world!"

syntax highlighting: