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

NAME

6       POE::Component - event driven objects or subsystems
7

SYNOPSIS

9       See specific components.
10

DESCRIPTION

12       POE "components" are event-driven modules that generally encapsulate
13       mid- to high-level program features.  For example,
14       POE::Component::Client::DNS performs message-based asynchronous
15       resolver lookups.  POE::Component::Server::TCP is a basic asynchronous
16       network server.
17
18       The POE::Component namespace was started as place for contributors to
19       publish their POE-based modules without requiring coordination with the
20       main POE distribution.  The namespace predates the -X convention,
21       otherwise you'd be reading about POEx instead.
22
23       As with many things in Perl, there is more than one way to implement
24       component interfaces.  Newer components sport OO interfaces, and some
25       even use Moose, but older ones are solely message driven.
26

OBJECT ORIENTED COMPONENTS

28       One way to create object-oriented components is to embed a POE::Session
29       instance within an object.  This is done by creating the session during
30       the object's constructor, and setting the session's alias to a
31       stringified version of the object reference.
32
33         package Asynchrotron;
34
35         sub new {
36           my $class = shift;
37           my $self = bless { }, $class;
38           POE::Session->create(
39             object_states => [
40               $self => {
41                 _start       => "_poe_start",
42                 do_something => "_poe_do_something",
43               },
44             ],
45           );
46           return $self;
47         }
48
49         sub _poe_start {
50           $_[KERNEL]->alias_set("$_[OBJECT]");
51         }
52
53       The alias allows object methods to pass events into the session without
54       having to store something about the session.  The POE::Kernel call()
55       transfers execution from the caller session's context into the
56       component's session.
57
58         sub do_something {
59           my $self = shift;
60           print "Inside the caller's session right now: @_\n";
61           $poe_kernel->call("$self", "do_something", @_);
62         }
63
64         sub _poe_do_something {
65           my @args = @_[ARG0..$#_];
66           print "Inside the component's session now: @args\n";
67           $_[OBJECT]{count}++;
68         }
69
70       Both $_[HEAP] and $_[OBJECT] are visible within the component's
71       session.  $_[HEAP] can be used for ultra-private encapsulation, while
72       $_[OBJECT] may be used for data visible by accessors.
73
74         sub get_count {
75           my $self = shift;
76           return $self->{count}; # $_[OBJECT]{count} above
77         }
78
79       Too many sessions may bog down object creation and destruction, so
80       avoid creating them for every object.
81

SEE ALSO

83       The SEE ALSO section in POE contains a table of contents covering the
84       entire POE distribution.
85
86       POE::Stage is a nascent project to formalize POE components, make
87       POE::Kernel more object-oriented, and provide syntactic and semantic
88       sugar for many common aspects of POE::Component development.  It's also
89       easier to type.  Please investigate the project.  Ideas and tuits are
90       badly needed to help get the project off the ground.
91

TO DO

93       Document the customary (but not mandatory!) process of creating and
94       publishing a component.
95

AUTHORS & COPYRIGHTS

97       Each component is written and copyrighted separately.
98
99       Please see POE for more information about authors and contributors.
100
101
102
103perl v5.12.1                      2010-04-03                 POE::Component(3)
Impressum