home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / POE.pm < prev    next >
Encoding:
Perl POD Document  |  2004-06-04  |  17.6 KB  |  528 lines

  1. # $Id: POE.pm,v 1.177 2004/06/03 22:10:58 rcaputo Exp $
  2. # Copyrights and documentation are after __END__.
  3.  
  4. package POE;
  5.  
  6. use strict;
  7. use Carp;
  8.  
  9. use vars qw($VERSION $REVISION);
  10. $VERSION = '0.29';
  11. $REVISION = do {my@r=(q$Revision: 1.177 $=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
  12.  
  13. sub import {
  14.   my $self = shift;
  15.  
  16.   my @sessions = grep(/^(Session|NFA)$/, @_);
  17.   my @modules = grep(!/^(Kernel|Session|NFA)$/, @_);
  18.  
  19.   croak "POE::Session and POE::NFA export conflicting constants"
  20.     if grep(/^(Session|NFA)$/, @sessions) > 1;
  21.  
  22.   # If a session was specified, use that.  Otherwise use Session.
  23.   if (@sessions) {
  24.     unshift @modules, @sessions;
  25.   }
  26.   else {
  27.     unshift @modules, 'Session';
  28.   }
  29.  
  30.   # Add Kernel back in, whether anybody wanted it or not.  Ensure that
  31.   # it comes before any sessions, since the sessions need to refer to
  32.   # constants defined in Kernel's namespace.
  33.   unshift @modules, 'Kernel';
  34.  
  35.   my $package = (caller())[0];
  36.  
  37.   my @failed;
  38.   foreach my $module (@modules) {
  39.     my $code = "package $package; use POE::$module;";
  40.     eval($code);
  41.     if ($@) {
  42.       warn $@;
  43.       push(@failed, $module);
  44.     }
  45.   }
  46.  
  47.   @failed and croak "could not import qw(" . join(' ', @failed) . ")";
  48. }
  49.  
  50. #------------------------------------------------------------------------------
  51.  
  52. sub new {
  53.   my $type = shift;
  54.   croak "$type is not meant to be used directly";
  55. }
  56.  
  57. #------------------------------------------------------------------------------
  58. 1;
  59.  
  60. __END__
  61.  
  62. =head1 NAME
  63.  
  64. POE - portable multitasking and networking framework for Perl
  65.  
  66. =head1 SYNOPSIS
  67.  
  68.   #!/usr/bin/perl -w
  69.   use strict;
  70.  
  71.   # Use POE!
  72.   use POE;
  73.  
  74.   sub handler_start {
  75.     my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
  76.     print "Session ", $session->ID, " has started.\n";
  77.     $heap->{count} = 0;
  78.     $kernel->yield('increment');
  79.   }
  80.  
  81.   sub handler_increment {
  82.     my ($kernel, $heap, $session) = @_[KERNEL, HEAP, SESSION];
  83.     print "Session ", $session->ID, " counted to ", ++$heap->{count}, ".\n";
  84.     $kernel->yield('increment') if $heap->{count} < 10;
  85.   }
  86.  
  87.   sub handler_stop {
  88.     print "Session ", $_[SESSION]->ID, " has stopped.\n";
  89.   }
  90.  
  91.   for (1..10) {
  92.     POE::Session->create(
  93.       inline_states => {
  94.         _start    => \&handler_start,
  95.         increment => \&handler_increment,
  96.         _stop     => \&handler_stop,
  97.       }
  98.     );
  99.   }
  100.  
  101.   POE::Kernel->run();
  102.   exit;
  103.  
  104. =head1 DESCRIPTION
  105.  
  106. POE is a framework for cooperative, event driven multitasking in Perl.
  107. Other languages have similar frameworks.  Python has Twisted.  TCL has
  108. "the event loop".
  109.  
  110. POE originally was developed as the core of a persistent object server
  111. and runtime environment.  It has evolved into a general purpose
  112. multitasking and networking framework, encompassing and providing a
  113. consistent interface to other event loops such as Event and the Tk and
  114. Gtk toolkits.
  115.  
  116. POE is written in layers, each building upon the previous.  It's
  117. therefore possible to use POE at varying levels of abstraction.
  118.  
  119. The lowest level uses POE::Kernel and POE::Session.  The former class
  120. acts as POE's event watcher and dispatcher.  The latter encapsulates
  121. the notion of an event driven task.
  122.  
  123. POE::Wheel classes operate at a slightly higher level.  They plug into
  124. sessions and perform very common, general tasks.  For example,
  125. POE::Wheel::ReadWrite performs buffered I/O.  
  126.  
  127. Unlike cheese, wheels do not stand alone.  They are customized by
  128. POE::Driver and POE::Filter classes.  Using the proper filter, a
  129. ReadWrite wheel can read and write streams, lines, fixed-length
  130. blocks, HTTP requests and responses, and so on.
  131.  
  132. The highest level of POE programming uses components.  They may
  133. perform narrowly defined tasks, such as POE::Component::Child (on the
  134. CPAN).  Often they encapsulate nearly everything necessary for an
  135. entire program.
  136.  
  137. Every level eventually boils down to the lowest common
  138. denominator---POE::Kernel and POE::Session.  Because of this, classes
  139. coexist and cooperate at every level of abstraction.
  140.  
  141. =head1 DOCUMENTATION ROADMAP
  142.  
  143. POE's documentation rewards the methodical reader.  Skim everything,
  144. and you should have a pretty good idea of what's available and where
  145. to find it later.
  146.  
  147. You're reading the main POE document.  It's the general entry point to
  148. POE's documentation.
  149.  
  150. Documentation for POE's basic features is spread across POE::Kernel
  151. and POE::Session in non-intuitive ways.  POE turns out to be difficult
  152. to document from either module's perspective, so there is a lot of
  153. overlap and cross-referencing.  We have plans to rewrite them, but
  154. that only helps if you want to join in the fun.
  155.  
  156. POE::NFA is a second kind of session---a Non-deterministic Finite
  157. Automaton class, which happens to be driven by events.  This is an
  158. abstract state machine, which can be either Mealy or Moore (or a
  159. little bit of both, or neither) depending on how it's configured.
  160.  
  161. POE::Wheel, POE::Driver, POE::Filter, and POE::Component describe
  162. entire classes of modules in broad strokes.  Where applicable, they
  163. document the features common among their subclasses.  This is
  164. confusing, since most people are inclined to read POE::Wheel::Foo and
  165. assume that something doesn't exist if it's not there.
  166.  
  167. There are also some helper classes.  POE::Pipe is the base class for
  168. POE::Pipe::OneWay and POE::Pipe::TwoWay.  They are portable pipe
  169. creation functions, mainly for POE's test suite.  POE::Preprocessor is
  170. a macro language implemented as a source filter.
  171.  
  172. POE is a relatively large system.  It includes internal classes that
  173. allow it to be customized without needing to know too much about the
  174. system as a whole.  POE::Queue describes POE's event queue interface.
  175. POE::Loop covers the commonalities of every event loop POE supports.
  176. POE::Resource discusses the notion of system resources, which
  177. correspond to event watchers and generators in other systems.
  178.  
  179. The SEE ALSO sections of each major module class will list the
  180. subclasses beneath it.  This document's SEE ALSO lists every module in
  181. the distribution.
  182.  
  183. Finally, there are many POE resources on the web.  The CPAN contains a
  184. growing number of POE modules.  POE's wiki, at
  185. L<http://poe.perl.org/>, includes tutorials, an extensive set of
  186. examples, documentation, and more.
  187.  
  188. =head1 COMPATIBILITY ISSUES
  189.  
  190. The developers of POE strive to make it as portable as possible.  If
  191. you discover a problem, please e-mail a report to
  192. <bug-POE@rt.cpan.org>.  If you can, include error messages, C<perl -V>
  193. output, and/or test cases.  The more information you can provide, the
  194. quicker we can turn around a fix.  Patches are also welcome, of
  195. course.
  196.  
  197. POE is known to work on FreeBSD, MacOS X, Linux, Solaris, and other
  198. forms of UNIX.  It also works to one extent or another on various
  199. versions of Windows, including 98, ME, NT, 2000, and XP.  It should
  200. work on OS/2, although we no longer have a developer who uses it.  It
  201. has been reported to work on MacOS 9, of all things.
  202.  
  203. POE has been tested with Perl versions as far back as 5.004_03 and as
  204. recent as 5.8.3.
  205.  
  206. Thanks go out to the CPAN testers, who have dedicated resources to
  207. running new modules on a variety of platforms.  The latest POE tests
  208. are visible at <http://testers.cpan.org/search?request=dist&dist=POE>.
  209.  
  210. We maintain our own test results at <http://eekeek.org/poe-tests/>.
  211. You may participate by running
  212.  
  213.   perl Makefile.PL
  214.   make uploadreport
  215.  
  216. from POE's source directory.  A set of tests will be run, and their
  217. results will be uploaded to our test page.
  218.  
  219. We also try to cover all of POE with our test suite, although we only
  220. succeed in exercising about 70% of its code at any given time.  A
  221. coverage report is online at
  222. <http://poe.perl.org/?POE's_test_coverage_report>.
  223.  
  224. Specific issues:
  225.  
  226. =over 2
  227.  
  228. =item Various Unices
  229.  
  230. No known problems.
  231.  
  232. =item OS/2
  233.  
  234. No known problems.  POE has no OS/2 tester as of version 0.1206.
  235.  
  236. =item Windows
  237.  
  238. POE seems to work very nicely with Perl compiled for CygWin.  If you
  239. must use ActiveState Perl, please use build 631 or newer.
  240.  
  241. POE's Windows port is current maintained by Rocco Caputo, but he has
  242. only limited knowledge of Windows development.  Please contact Rocco
  243. if you or someone you know would like to accelerate POE's Windows
  244. support.
  245.  
  246. Sean Puckett, Douglas Couch, and Andrew Chen have helped to bring
  247. POE's Windows support this far.
  248.  
  249. TODO: I'm sure there are others.  Find them in the changelog and thank
  250. them here.
  251.  
  252. =item MacOS
  253.  
  254. No known problems on MacOS X.
  255.  
  256. Mac Classic (versions 9.x and before) was reported to work at one
  257. time, but it seems like a lost cause unless someone would like to step
  258. forward and make it happen.
  259.  
  260. =back
  261.  
  262. =head1 SYSTEM REQUIREMENTS
  263.  
  264. POE has only one absolute external requirement: Filter::Util::Call
  265. version 1.04 or later.  All the other modules are optional, although
  266. people tend to install them anyway.
  267.  
  268. POE's installer will prompt for required and optional modules.  It's
  269. important to read the prompts and only install what you will need.
  270. You may always reinstall it later, adding new prerequisites as the
  271. need arises.  B<Note that Tk and Gtk support require very large
  272. dependencies.>
  273.  
  274. Time::HiRes is recommended.  POE will work without it, but alarms and
  275. other features will be much more accurate with it.
  276.  
  277. POE::Wheel::Run requires a working fork() implementation.
  278. Unfortunately ActivePerl's fork() emulation is not sufficient for it.
  279. CygWin's fork() works just fine however.
  280.  
  281. POE relies heavily on constants in the POSIX module.  Some of the
  282. constants aren't defined on some platforms.  POE works around this as
  283. best it can, but problems occasionally crop up.  Please let us know if
  284. you run into problems, and we'll work with you to fix them.
  285.  
  286. Filter::Reference needs a module to serialize data for transporting it
  287. across a network.  It will use Storable, FreezeThaw, YAML, or some
  288. other package with freeze() and thaw() methods.  It can also use
  289. Compress::Zlib to conserve bandwidth and reduce latency over slow
  290. links, but it's not required.
  291.  
  292. If you want to write web servers, you'll need to install libwww-perl,
  293. which requires libnet.  This is a small world of modules that includes
  294. HTTP::Status, HTTP::Request, HTTP::Date, and HTTP::Response.  They are
  295. generally good to have, and recent versions of Perl include them.
  296.  
  297. Programs that use Wheel::Curses require the Curses module, which in
  298. turn requires some sort of curses library.
  299.  
  300. =head1 SUPPORT RESOURCES
  301.  
  302. These are Internet resources where you may find more information about
  303. POE.
  304.  
  305. =over 2
  306.  
  307. =item POE's Request Tracker
  308.  
  309. Bug reports, suggestions, and feedback of all kinds should be e-mailed
  310. to <bug-POE@rt.cpan.org>.  It will be entered into our request queue
  311. where it will remain until addressed.  If your return address is
  312. valid, you will be notified when the status of your request changes.
  313.  
  314. =item POE's Mailing List
  315.  
  316. POE has a mailing list where you can discuss it with the community at
  317. large.  You can receive subscription information by sending e-mail:
  318.  
  319.   To: poe-help@perl.org
  320.   Subject: (anything will do)
  321.  
  322. The message body is ignored.
  323.  
  324. =item POE's Web Site
  325.  
  326. POE's web site contains the latest development snapshot along with
  327. examples, tutorials, and other fun stuff.  It's at
  328. <http://poe.perl.org/>.
  329.  
  330. =item SourceForge
  331.  
  332. POE is developed at SourceForge.  The project is hosted at
  333. http://sourceforge.net/projects/poe/
  334.  
  335. =back
  336.  
  337. =head1 SEE ALSO
  338.  
  339. POE::Kernel, POE::Session, POE::NFA
  340.  
  341. POE::Wheel, POE::Wheel::Curses, POE::Wheel::FollowTail,
  342. POE::Wheel::ListenAccept, POE::Wheel::ReadLine, POE::Wheel::ReadWrite,
  343. POE::Wheel::Run, POE::Wheel::SocketFactory
  344.  
  345. POE::Driver, POE::Driver::SysRW
  346.  
  347. POE::Filter, POE::Filter::Block, POE::Filter::Grep,
  348. POE::Filter::HTTPD, POE::Filter::Line, POE::Filter::Map,
  349. POE::Filter::RecordBlock, POE::Filter::Reference,
  350. POE::Filter::Stackable, POE::Filter::Stream
  351.  
  352. POE::Component, POE::Component::Client::TCP,
  353. POE::Component::Server::TCP
  354.  
  355. POE::Loop, POE::Loop::Event, POE::Loop::Gtk, POE::Loop::Poll,
  356. POE::Loop::Select, POE::Loop::Tk
  357.  
  358. POE::Pipe, POE::Pipe::OneWay, POE::Pipe::TwoWay
  359.  
  360. POE::Preprocessor
  361.  
  362. POE::Queue, POE::Queue::Array
  363.  
  364. POE::Resource, POE::Resource::Aliases, POE::Resource::Events,
  365. POE::Resource::Extrefs, POE::Resource::FileHandles,
  366. POE::Resource::Performance, POE::Resource::SIDs,
  367. POE::Resource::Sessions, POE::Resource::Signals
  368.  
  369. =head1 BUGS
  370.  
  371. The t/*.t tests only cover about 70% of POE.
  372.  
  373. Outstanding issues, including wish list items, are available in POE's
  374. queue at L<http://rt.cpan.org/>.
  375.  
  376. =head1 AUTHORS & COPYRIGHT
  377.  
  378. POE is the combined effort of several people.  Please let us know if
  379. someone is missing from this list.
  380.  
  381. TODO: Scour the CHANGES file for credit where it's due.
  382.  
  383. =over 2
  384.  
  385. =item Ann Barcomb
  386.  
  387. Ann Barcomb is <kudra@domaintje.com>, aka C<kudra>.  Ann contributed
  388. large portions of POE::Simple and the code that became the ReadWrite
  389. support in POE::Component::Server::TCP.  Her ideas also inspired
  390. Client::TCP component, introduced in version 0.1702.
  391.  
  392. =item Artur Bergman
  393.  
  394. Artur Bergman is <sky@cpan.org>.  He contributed many hours' work into
  395. POE and quite a lot of ideas.  Years later, I decide he's right and
  396. actually implement them.
  397.  
  398. Artur is the author of Filter::HTTPD and Filter::Reference, as well as
  399. bits and pieces throughout POE.  His feedback, testing, design and
  400. inspiration have been instrumental in making POE what it is today.
  401.  
  402. Artur is investing his time heavily into perl 5's iThreads and PONIE
  403. at the moment.  This project has far-reaching implications for POE's
  404. future.
  405.  
  406. =item Jos Boumans
  407.  
  408. Jos Boumans is <boumans@frg.eur.nl>, aka C<Co-Kane>.  Jos is a major
  409. driving force behind the POE::Simple movement and has helped inspire
  410. the POE::Components for TCP clients and servers.
  411.  
  412. =item Matt Cashner
  413.  
  414. Matt Cashner is <sungo@pobox.com>, aka C<sungo>.  Matt is one of POE's
  415. core developers.  He's spearheaded the movement to simplify POE for
  416. new users, flattening the learning curve and making the system more
  417. accessible to everyone.  He uses the system in mission critical
  418. applications, folding feedback and features back into the distribution
  419. for everyone's enjoyment.
  420.  
  421. =item Andrew Chen
  422.  
  423. Andrew Chen is <achen-poe@micropixel.com>.  Andrew is the resident
  424. POE/Windows guru.  He contributes much needed testing for Solaris on
  425. the SPARC and Windows on various Intel platforms.
  426.  
  427. =item Douglas Couch
  428.  
  429. Douglas Couch is <dscouch@purdue.edu>.  Douglas helped port and
  430. maintain POE for Windows early on.
  431.  
  432. =item Jeffrey Goff
  433.  
  434. Jeffrey Goff is <jgoff@blackboard.com>.  Jeffrey is the author of
  435. several POE modules, including a tokenizing filter and a component for
  436. managing user information, PoCo::UserBase.  He's also co-author of "A
  437. Beginner's Introduction to POE" at www.perl.com.
  438.  
  439. =item Philip Gwyn
  440.  
  441. Philip Gwyn is <gwynp@artware.qc.ca>.  He extended the Wheels I/O
  442. abstraction to support hot-swappable filters, and he eventually
  443. convinced Rocco that unique session and kernel IDs were a good thing.
  444.  
  445. Philip also enhanced Filter::Reference to support different
  446. serialization methods.  He has also improved POE's quality by finding
  447. and fixing several bugs.  He provided POE a much needed code review
  448. around version 0.06.
  449.  
  450. =item Arnar M. Hrafnkelsson
  451.  
  452. Arnar is <addi@umich.edu>.  Addi tested POE and POE::Component::IRC on
  453. Windows, finding bugs and testing fixes.  He appears throughout the
  454. Changes file.  He has also written "cpoe", which is a POE-like library
  455. for C.
  456.  
  457. =item Dave Paris
  458.  
  459. Dave Paris is <dparis@w3works.com>.  Dave tested and benchmarked POE
  460. around version 0.05, discovering some subtle (and not so subtle)
  461. timing problems.  The pre-forking server sample was his idea.
  462. Versions 0.06 and later scaled to higher loads because of his work.
  463. He has contributed a lot of testing and feedback, much of which is
  464. tagged in the Changes file as a-mused.  The man is scarily good at
  465. testing and troubleshooting.
  466.  
  467. =item Dieter Pearcey
  468.  
  469. Dieter Pearcey is <dieter@bullfrog.perlhacker.org>.  He goes by
  470. several Japanese nicknames.  Dieter's current area of expertise is in
  471. Wheels and Filters.  He greatly improved Wheel::FollowTail, and his
  472. Filter contributions include the basic Block filter, as well as
  473. Stackable, RecordBlock, Grep and Map.
  474.  
  475. =item Robert Seifer
  476.  
  477. Robert Seifer is <e-mail unknown>.  He rotates IRC nicknames
  478. regularly.
  479.  
  480. Robert contributed entirely too much time, both his own and his
  481. computers, towards the detection and eradication of a memory
  482. corruption bug that POE tickled in earlier Perl versions.  In the end,
  483. his work produced a simple compile-time hack that worked around a
  484. problem relating to anonymous subs, scope and @{} processing.
  485.  
  486. =item Matt Sergeant
  487.  
  488. Matt contributed POE::Kernel::Poll, a more efficient way to watch
  489. multiple files than select().
  490.  
  491. =item Richard Soderberg
  492.  
  493. Richard Soderberg is <poe@crystalflame.net>, aka C<coral>.  Richard is
  494. a collaborator on several side projects involving POE.  His work
  495. provides valuable testing and feedback from a user's point of view.
  496.  
  497. =item Dennis Taylor
  498.  
  499. Dennis Taylor is <dennis@funkplanet.com>.  Dennis has been testing,
  500. debugging and patching bits here and there, such as Filter::Line which
  501. he improved by leaps in 0.1102.  He's also the author of
  502. POE::Component::IRC, the widely popular POE-based successor to his
  503. wildly popular Net::IRC library.
  504.  
  505. =item Others?
  506.  
  507. Please contact the author if you've been forgotten.
  508.  
  509. =back
  510.  
  511. =head2 Author
  512.  
  513. =over 2
  514.  
  515. =item Rocco Caputo
  516.  
  517. Rocco Caputo is <rcaputo@cpan.org>.  POE is his brainchild.
  518.  
  519. Except where otherwise noted, POE is Copyright 1998-2004 Rocco Caputo.
  520. All rights reserved.  POE is free software; you may redistribute it
  521. and/or modify it under the same terms as Perl itself.
  522.  
  523. =back
  524.  
  525. Thank you for reading!
  526.  
  527. =cut
  528.