Permalink
Browse files

Start accumulating small example programs for tutorials.

  • Loading branch information...
1 parent 8d76055 commit 076f3d826aa398be9f2c64cd83f646461d34dc69 @rcaputo committed Mar 23, 2010
Showing with 45 additions and 0 deletions.
  1. +19 −0 small-programs/looping-hello.pl
  2. +26 −0 small-programs/timed-looping-hello.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use POE;
+
+POE::Session->create(
+ inline_states => {
+ _start => \&say_what,
+ say_what_again => \&say_what,
+ },
+);
+
+POE::Kernel->run();
+
+sub say_what {
+ print "what\n";
+ $_[KERNEL]->yield("say_what_again");
+}
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use POE;
+
+sub start_saying {
+ my ($what, $delay) = @_;
+
+ my $say_it = sub {
+ print "$what\n";
+ $_[KERNEL]->delay(say_it_again => $delay);
+ };
+
+ POE::Session->create(
+ inline_states => {
+ _start => $say_it,
+ say_it_again => $say_it,
+ },
+ );
+}
+
+start_saying("hello", 1);
+start_saying(" world", 1.5);
+
+POE::Kernel->run();

0 comments on commit 076f3d8

Please sign in to comment.