1POE(3)                User Contributed Perl Documentation               POE(3)
2
3
4

NAME

6       POE - portable multitasking and networking framework for any event loop
7

SYNOPSIS

9         #!/usr/bin/perl -w
10         use strict;
11
12         use POE;  # Auto-includes POE::Kernel and POE::Session.
13
14         sub handler_start {
15           my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
16           print "Session ", $session->ID, " has started.\n";
17           $heap->{count} = 0;
18           $kernel->yield('increment');
19         }
20
21         sub handler_increment {
22           my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
23           print "Session ", $session->ID, " counted to ", ++$heap->{count}, ".\n";
24           $kernel->yield('increment') if $heap->{count} < 10;
25         }
26
27         sub handler_stop {
28           print "Session ", $_[SESSION]->ID, " has stopped.\n";
29         }
30
31         for (1..10) {
32           POE::Session->create(
33             inline_states => {
34               _start    => \&handler_start,
35               increment => \&handler_increment,
36               _stop     => \&handler_stop,
37             }
38           );
39         }
40
41         POE::Kernel->run();
42         exit;
43

DESCRIPTION

45       POE is a framework for cooperative, event driven multitasking and
46       networking in Perl.  Other languages have similar frameworks.  Python
47       has Twisted.  TCL has "the event loop".
48
49       POE provides a unified interface for several other event loops,
50       including select(), IO::Poll, Glib, Gtk, Tk, Wx, and Gtk2.  Many of
51       these event loop interfaces were written by others, with the help of
52       POE::Test::Loops.  They may be found on the CPAN.
53
54       POE achieves its its high degree of portability to different operating
55       systems and Perl versions by being written entirely in Perl.  CPAN
56       hosts optional XS modules for POE if speed is more desirable than
57       portability.
58
59       POE is designed in layers.  Each layer builds atop the lower level
60       ones.  Programs are free to use POE at any level of abstraction, and
61       different levels can be mixed and matched seamlessly within a single
62       program.  Remember, though, that higher-level abstractions often
63       require more resources than lower-level ones.  The conveniences they
64       provide are not free.
65
66       POE's bundled abstraction layers are the tip of a growing iceberg.
67       Sprocket, POE::Stage, and other CPAN distributions build upon this
68       work.  You're encouraged to look around.
69
70       No matter how high you go, though, it all boils down to calls to
71       POE::Kernel.  So your down-to-earth code can easily cooperate with
72       stratospheric systems.
73
74   Layer 1: Kernel and Sessions
75       The lowest public layer is comprised of POE::Kernel, POE::Session, and
76       other session types.
77
78       POE::Kernel does most of the heavy lifting.  It provides a portable
79       interface for filehandle activity detection, multiple alarms and other
80       timers, signal handling, and other less-common features.
81
82       POE::Session and derived classes encapsulate the notion of an event
83       driven task.  They also customize event dispatch to a particular
84       calling convention.  POE::NFA, for example, is more of a proper state
85       machine.  The CPAN has several other kinds of sessions.
86
87       Everything ultimately builds on these classes or the concepts they
88       implement.  If you're short on time, the things to read besides this
89       are POE::Kernel and POE::Session.
90
91   Layer 2: Wheels, Filters, and Drivers
92       POE::Wheel objects are dynamic mix-ins for POE::Session instances.
93       These "wheels" perform very common, generic tasks in a highly reusable
94       and customizable way.  POE::Wheel::ReadWrite, for example, implements
95       non-blocking buffered I/O.  Nearly everybody needs this, so why require
96       people to reinvent it all the time?
97
98       POE::Filter objects customize wheels in a modular way.  Filters act as
99       I/O layers, turning raw streams into structured data, and serializing
100       structures into something suitable for streams.  The CPAN also has
101       several of these.
102
103       Drivers are where the wheels meet the road.  In this case, the road is
104       some type of file handle.  Drivers do the actual reading and writing in
105       a standard way so wheels don't need to know the difference between
106       send() and syswrite().
107
108       POE::Driver objects get relatively short shrift because very few are
109       needed.  The most common driver, POE::Driver::SysRW is ubiquitous and
110       also the default, so most people will never need to specify one.
111
112   Layer 3: Components
113       POE::Component classes are essentially Perl classes that use POE to
114       perform tasks in a non-blocking or cooperative way.  This is a very
115       broad definition, and POE components are all over the abstraction map.
116
117       Many components, such as POE::Component::Server::SMTP, encapsulate the
118       generic details of an entire application.  Others perform rather narrow
119       tasks, such as POE::Component::DirWatch::Object.
120
121       POE components are often just plain Perl objects.  The previously
122       mentioned POE::Component::DirWatch::Object uses Moose.  Other object
123       and meta-object frameworks are compatible.
124
125       Also of interest is POE::Component::Generic, which is allows you to
126       create a POE component from nearly nearly any blocking module.
127
128       There are quite a lot of components on the CPAN.
129       <http://search.cpan.org/search?query=poe+component&mode=all>
130
131   Layer 4 and Beyond: Frameworks and Object Metaphors
132       It's possible to abstract POE entirely behind a different framework.
133       In fact we encourage people to write domain-specific abstractions that
134       entirely hide POE if necessary.  The nice thing here is that even at
135       these high levels of abstraction, things will continue to interoperate
136       all the way down to layer 1.
137
138       Two examples of ultra-high level abstraction are Sprocket, a networking
139       framework that does its own thing, and POE::Stage, which is POE's
140       creator's attempt to formalize and standardize POE components.
141
142       It is also possible to communicate between POE processes.  This is
143       called IKC, for Inter-Kernel Communication.  There are a few IKC
144       components on the CPAN
145       (<http://search.cpan.org/search?query=IKC&mode=all>), notably
146       POE::Component::IKC and POE::TIKC.
147
148   Layer 0: POE's Internals
149       POE's layered architecture continues below the surface.  POE's guts are
150       broken into specific POE::Loop classes for each event loop it supports.
151       Internals are divided up by type, giving POE::Resource classes for
152       Aliases, Controls, Events, Extrefs, FileHandles, SIDs, Sessions,
153       Signals, and Statistics.
154
155       POE::Kernel's APIs are extensible through POE::API mix-in classes.
156       Some brave souls have even published new APIs on CPAN, such as
157       POE::API::Peek (which gives you access to some of the internal
158       POE::Resource methods).
159
160       By design, it's possible to implement new POE::Kernel guts by creating
161       another POE::Resource class.  One can then expose the functionality
162       with a new POE::API mix-in.
163

DOCUMENTATION ROADMAP

165       You're reading the main POE documentation.  It's the general entry
166       point to the world of POE.  You already know this, however, so let's
167       talk about something more interesting.
168
169   Basic Features
170       POE's basic features are documented mainly in POE::Kernel and
171       POE::Session.  Methods are documented in the classes that implement
172       them.  Broader concepts are covered in the most appropriate class, and
173       sometimes they are divided among classes that share in their
174       implementation.
175
176   Basic Usage
177       Basic usage, even for POE.pm, is documented in POE::Kernel.  That's
178       where most of POE's work is done, and POE.pm is little more than a
179       class loader.
180
181   @_[KERNEL, HEAP, etc.]
182       Event handler calling conventions, that weird @_[KERNEL, HEAP] stuff,
183       is documented in POE::Session.  That's because POE::Session implements
184       the calling convention, and other session types often do it
185       differently.
186
187   Base Classes Document Common Features
188       The POE::Wheel, POE::Driver, POE::Filter, and POE::Component base
189       classes describe what's common among each class.  It's a good idea to
190       at least skim the base class documentation since the subclasses tend
191       not to rehash the common things.
192
193       POE::Queue, POE::Resource, POE::Loop, and POE::API document the
194       concepts and sometimes the standard interfaces behind multiple
195       subclasses.  You're encouraged to have a look.
196
197   Helper Classes
198       POE includes some helper classes for portability.  POE::Pipe, and its
199       subclasses POE::Pipe::OneWay and POE::Pipe::TwoWay are portable pipes.
200
201   Event Loop Bridges
202       POE::Loop documents and specifies the interface for all of POE's event
203       loop bridges.  The individual classes may document specific details,
204       but generally they adhere to the spec strongly enough that they don't
205       need to.
206
207       Many of the existing POE::Loop bridges provided in POE's base
208       distribution will move out to separate distributions shortly.  The
209       documentation will probably remain the same, however.
210
211   POE::Queue and POE::Queue::Array
212       POE's event queue is basically a priority heap implemented as an
213       ordered array.  POE::Queue documents the standard interface for POE
214       event queues, and POE::Queue::Array implements the ordered array queue.
215       Tony Cook has released POE::XS::Queue::Array, which is a drop-in C
216       replacement for POE::Queue::Array.  You might give it a try if you need
217       more performance.  POE's event queue is some of the hottest code in the
218       system.
219
220   This Section Isn't Complete
221       Help organize the documentation.  Obviously we can't think of
222       everything.  We're well aware of this and welcome audience
223       participation.
224
225   See SEE ALSO
226       Wherever possible, the SEE ALSO section will cross-reference one module
227       to related ones.
228
229   Don't Forget the Web
230       Finally, there are many POE resources on the web.  The CPAN contains a
231       growing number of POE modules.  <http://poe.perl.org/> hosts POE's
232       wiki, which includes tutorials, an extensive set of examples,
233       documentation, and more.  Plus it's a wiki, so you can trivially pitch
234       in your two cents.
235

SYSTEM REQUIREMENTS

237       POE's basic requirements are rather light.  Most are included with
238       modern versions of Perl, and the rest (if any) should be generally
239       portable by now.
240
241       Time::HiRes is highly recommended, even for older Perls that don't
242       include it.  POE will work without it, but alarms and other features
243       will be much more accurate if it's included. POE::Kernel will use
244       Time::HiRes automatically if it's available.
245
246       POE::Filter::Reference needs a module to serialize data for
247       transporting it across a network.  It will use Storable, FreezeThaw,
248       YAML, or some other package with freeze() and thaw() methods.  It can
249       also use Compress::Zlib to conserve bandwidth and reduce latency over
250       slow links, but it's not required.
251
252       If you want to write web servers, you'll need to install libwww-perl,
253       which requires libnet.  This is a small world of modules that includes
254       HTTP::Status, HTTP::Request, HTTP::Date, and HTTP::Response.  They are
255       generally good to have, and modern versions of Perl even include them.
256
257       Programs that use POE::Wheel::Curses will of course require the Curses
258       module, which in turn requires some sort of curses library.
259
260       If you're using POE with Tk, you'll need Tk installed.
261
262       And other obvious things.  Let us know if we've overlooked a non-
263       obvious detail.
264

COMPATIBILITY ISSUES

266       One of POE's design goals is to be as portable as possible.  That's why
267       it's written in "Plain Perl".  XS versions of POE modules are available
268       as third-party distributions.  Parts of POE that require nonstandard
269       libraries are optional, and not having those libraries should not
270       prevent POE from installing.
271
272       Despite Chris Williams' efforts, we can't test POE everywhere.  Please
273       see the GETTING HELP section if you run into a problem.
274
275       POE is expected to work on most forms of UNIX, including FreeBSD, MacOS
276       X, Linux, Solaris.  Maybe even AIX and QNX, but we're not sure.
277
278       POE is also tested on Windows XP, using the latest version of
279       ActiveState, Strawberry and Cygwin Perl.  POE is fully supported with
280       Strawberry Perl, as it's included in the Strawberry distribution.
281
282       OS/2 and MacOS 9 have been reported to work in the past, but nobody
283       seems to be testing there anymore.  Reports and patches are still
284       welcome.
285
286       Past versions of POE have been tested with Perl versions as far back as
287       5.004_03 and as recent as "blead", today's development build.  We can
288       no longer guarantee each release will work everywhere, but we will be
289       happy to work with you if you need special support for a really old
290       system.
291
292       POE's quality is due in large part to the fine work of Chris Williams
293       and the other CPAN testers.  They have dedicated resources towards
294       ensuring CPAN distributions pass their own tests, and we watch their
295       reports religiously.  You can, too.  The latest POE test reports can be
296       found at <http://cpantesters.org/distro/P/POE.html>.
297
298       Thanks also go out to Benjamin Smith and the 2006 Google Summer of
299       Code.  Ben was awarded a grant to improve POE's test suite, which he
300       did admirably.
301
302   Windows Issues
303       POE seems to work very nicely with Perl compiled for Cygwin.  If you
304       must use ActiveState Perl, please use the absolute latest version.
305       ActiveState Perl's compatibility fluctuates from one build to another,
306       so we tend not to support older releases.
307
308       Windows and ActiveState Perl are considered an esoteric platform due to
309       the complex interactions between various versions.  POE therefore
310       relies on user feedback and support here.
311
312       A number of people have helped bring POE's Windows support this far,
313       through contributions of time, patches, and other resources.  Some of
314       them are: Sean Puckett, Douglas Couch, Andrew Chen, Uhlarik Ondoej,
315       Nick Williams, and Chris Williams (no relation).
316
317   Other Compatibility Issues
318       None currently known.  See GETTING HELP below if you've run into
319       something.
320

GETTING HELP

322       POE's developers take pride in its quality.  If you encounter a
323       problem, please let us know.
324
325   POE's Request Tracker
326       You're welcome to e-mail questions and bug reports to
327       <bug-POE@rt.cpan.org>.  This is not a realtime support channel, though.
328       If you need a more immediate response, try one of the methods below.
329
330   POE's Mailing List
331       POE has a dedicated mailing list where developers and users discuss the
332       software and its use.  You're welcome to join us.  Send an e-mail to
333       <poe-help@perl.org> for subscription instructions.  The subject and
334       message body are ignored.
335
336   POE's Web Site
337       <http://poe.perl.org> contains recent information, tutorials, and
338       examples.  It's also a wiki, so people are invited to share tips and
339       code snippets there as well.
340
341   POE's Source Code
342       The following command will fetch the most current version of POE into
343       the "poe" subdirectory:
344
345         svn co https://poe.svn.sourceforge.net/svnroot/poe poe
346
347   SourceForge
348       http://sourceforge.net/projects/poe/ is POE's project page.
349
350   Internet Relay Chat (IRC)
351       irc.perl.org channel #poe is an informal place to waste some time and
352       maybe even discuss Perl and POE.  Consider an SSH relay if your
353       workplace frowns on IRC.  But only if they won't fire you if you're
354       caught.
355
356   Personal Support
357       Unfortunately we don't have resources to provide free one-on-one
358       personal support anymore.  We'll do it for a fee, though.  Send Rocco
359       an e-mail via his CPAN address.
360

SEE ALSO

362       Broken down by abstraction layer.
363
364   Layer 1
365       POE::Kernel, POE::Session, POE::NFA
366
367   Layer 2
368       POE::Wheel, POE::Wheel::Curses, POE::Wheel::FollowTail,
369       POE::Wheel::ListenAccept, POE::Wheel::ReadLine, POE::Wheel::ReadWrite,
370       POE::Wheel::Run, POE::Wheel::SocketFactory
371
372       POE::Driver, POE::Driver::SysRW
373
374       POE::Filter, POE::Filter::Block, POE::Filter::Grep, POE::Filter::HTTPD,
375       POE::Filter::Line, POE::Filter::Map, POE::Filter::RecordBlock,
376       POE::Filter::Reference, POE::Filter::Stackable, POE::Filter::Stream
377
378   Layer 3
379       POE::Component, POE::Component::Client::TCP,
380       POE::Component::Server::TCP
381
382   Layer 0
383       POE::Loop, POE::Loop::Event, POE::Loop::Gtk, POE::Loop::IO_Poll,
384       POE::Loop::Select, POE::Loop::Tk
385
386       POE::Queue, POE::Queue::Array
387
388       POE::Resource, POE::Resource::Aliases, POE::Resource::Events,
389       POE::Resource::Extrefs, POE::Resource::FileHandles,
390       POE::Resource::Performance, POE::Resource::SIDs,
391       POE::Resource::Sessions, POE::Resource::Signals
392
393   Helpers
394       POE::Pipe, POE::Pipe::OneWay, POE::Pipe::TwoWay
395
396   Home Page
397       http://poe.perl.org/
398
399   Bug Tracker
400       https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=POE
401
402   Repository
403       https://poe.svn.sourceforge.net/svnroot/poe/trunk/poe
404
405   Other Resources
406       http://search.cpan.org/dist/POE/
407
409       POE is the combined effort of quite a lot of people.  This is an
410       incomplete list of some early contributors.  A more complete list can
411       be found in POE's change log.
412
413       Ann Barcomb
414         Ann Barcomb is <kudra@domaintje.com>, aka "kudra".  Ann contributed
415         large portions of POE::Simple and the code that became the ReadWrite
416         support in POE::Component::Server::TCP.  Her ideas also inspired
417         Client::TCP component, introduced in version 0.1702.
418
419       Artur Bergman
420         Artur Bergman is <sky@cpan.org>.  He contributed many hours' work
421         into POE and quite a lot of ideas.  Years later, I decide he's right
422         and actually implement them.
423
424         Artur is the author of Filter::HTTPD and Filter::Reference, as well
425         as bits and pieces throughout POE.  His feedback, testing, design and
426         inspiration have been instrumental in making POE what it is today.
427
428         Artur is investing his time heavily into perl 5's iThreads and PONIE
429         at the moment.  This project has far-reaching implications for POE's
430         future.
431
432       Jos Boumans
433         Jos Boumans is <kane@cpan.org>, aka "kane".  Jos is a major driving
434         force behind the POE::Simple movement and has helped inspire the
435         POE::Components for TCP clients and servers.
436
437       Matt Cashner
438         Matt Cashner is <sungo@pobox.com>, aka "sungo".  Matt is one of POE's
439         core developers.  He's spearheaded the movement to simplify POE for
440         new users, flattening the learning curve and making the system more
441         accessible to everyone.  He uses the system in mission critical
442         applications, folding feedback and features back into the
443         distribution for everyone's enjoyment.
444
445       Andrew Chen
446         Andrew Chen is <achen-poe@micropixel.com>.  Andrew is the resident
447         POE/Windows guru.  He contributes much needed testing for Solaris on
448         the SPARC and Windows on various Intel platforms.
449
450       Douglas Couch
451         Douglas Couch is <dscouch@purdue.edu>.  Douglas helped port and
452         maintain POE for Windows early on.
453
454       Jeffrey Goff
455         Jeffrey Goff is <jgoff@blackboard.com>.  Jeffrey is the author of
456         several POE modules, including a tokenizing filter and a component
457         for managing user information, PoCo::UserBase.  He's also co-author
458         of "A Beginner's Introduction to POE" at www.perl.com.
459
460       Philip Gwyn
461         Philip Gwyn is <gwynp@artware.qc.ca>.  He extended the Wheels I/O
462         abstraction to support hot-swappable filters, and he eventually
463         convinced Rocco that unique session and kernel IDs were a good thing.
464
465         Philip also enhanced POE::Filter::Reference to support different
466         serialization methods.  He has also improved POE's quality by finding
467         and fixing several bugs.  He provided POE a much needed code review
468         around version 0.06.
469
470         Lately, Philip tracked down the race condition in signal handling and
471         fixed it with the signal pipe.
472
473       Arnar M. Hrafnkelsson
474         Arnar is <addi@umich.edu>.  Addi tested POE and POE::Component::IRC
475         on Windows, finding bugs and testing fixes.  He appears throughout
476         the Changes file.  He has also written "cpoe", which is a POE-like
477         library for C.
478
479       Dave Paris
480         Dave Paris is <dparis@w3works.com>.  Dave tested and benchmarked POE
481         around version 0.05, discovering some subtle (and not so subtle)
482         timing problems.  The pre-forking server sample was his idea.
483         Versions 0.06 and later scaled to higher loads because of his work.
484         He has contributed a lot of testing and feedback, much of which is
485         tagged in the Changes file as a-mused.  The man is scarily good at
486         testing and troubleshooting.
487
488       Dieter Pearcey
489         Dieter Pearcey is <dieter@bullfrog.perlhacker.org>.  He goes by
490         several Japanese nicknames.  Dieter's current area of expertise is in
491         Wheels and Filters.  He greatly improved POE::Wheel::FollowTail, and
492         his Filter contributions include the basic Block filter, as well as
493         Stackable, RecordBlock, Grep and Map.
494
495       Robert Seifer
496         Robert Seifer is <e-mail unknown>.  He rotates IRC nicknames
497         regularly.
498
499         Robert contributed entirely too much time, both his own and his
500         computers, towards the detection and eradication of a memory
501         corruption bug that POE tickled in earlier Perl versions.  In the
502         end, his work produced a simple compile-time hack that worked around
503         a problem relating to anonymous subs, scope and @{} processing.
504
505       Matt Sergeant
506         Matt contributed POE::Kernel::Poll, a more efficient way to watch
507         multiple files than select().  It's since been moved to
508         POE::Loop::IO_Poll.
509
510       Richard Soderberg
511         Richard Soderberg is <poe@crystalflame.net>, aka "coral".  Richard is
512         a collaborator on several side projects involving POE.  His work
513         provides valuable testing and feedback from a user's point of view.
514
515       Dennis Taylor
516         Dennis Taylor is <dennis@funkplanet.com>.  Dennis has been testing,
517         debugging and patching bits here and there, such as Filter::Line
518         which he improved by leaps in 0.1102.  He's also the author of
519         POE::Component::IRC, the widely popular POE-based successor to his
520         wildly popular Net::IRC library.
521
522       David Davis
523         David Davis, aka Xantus is <xantus@cpan.org>.  David contributed
524         patches to the HTTPD filter, and added CALLER_STATE to POE::Session.
525         He is the author of Sprocket, a networking framework built on POE.
526
527       Others?
528         Please contact the author if you've been forgotten and would like to
529         be included here.
530
531         TODO - This section has fallen into disrepair.  A POE historian needs
532         to cull the CHANGES for the names of major contributors.
533
534   Author
535       Rocco Caputo
536         Rocco Caputo is <rcaputo@cpan.org>.  POE is his brainchild.  He
537         wishes to thank you for your interest, and he has more thanks than he
538         can count for all the people who have contributed.  POE would not be
539         nearly as cool without you.
540
541         Except where otherwise noted, POE is Copyright 1998-2009 Rocco
542         Caputo.  All rights reserved.  POE is free software; you may
543         redistribute it and/or modify it under the same terms as Perl itself.
544
545       Thank you for reading!
546
547
548
549perl v5.12.1                      2010-04-03                            POE(3)
Impressum