Chapter 7. POE

In this chapter, we’re going to look at what Mark-Jason Dominus called “the most interesting development in Perl 5”: the Perl Object Environment. POE has many goals and many uses; to give a few of them:

  • Provide a cooperative scheduling and multitasking environment rivalling threads and IPC

  • Simplify the development of protocol-driven network clients and servers

  • Provide an architecture for creating state machines

  • Abstract away a lot of the boring I/O details from complex programs

As you can see, POE is a difficult thing to describe,[*] but the main point is that POE attempts to hide the menial details of event-driven programming.

Programming in an Event-Driven Environment

If you’ve ever programmed a graphical application using something like Tk or Gtk, you’ll know that it’s a little different than ordinary procedural programming. In normal programming, you write a sequence of things you’d like the program to do, and it does them. However, GUIs don’t work like that—instead, you set up an environment (a window, for instance) that responds to certain events (clicking a button or selecting a menu item). This is called the event-driven paradigm .

It’s not just GUIs that use this paradigm. For example, a network server does not do a sequence of events, but it sits waiting for a connection (an event), and then services the connection depending on the input from the client. When the client is done and disconnects, it goes back to waiting for the next event.

Similarly, you could write ...

Get Advanced Perl Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.