------------------------------------------------ On Wed, 27 Aug 2003 12:44:18 -0500, "Jake" <[EMAIL PROTECTED]> wrote:
> Is this question so basic no one wants to answer, or is no one listening (I > fear the first) > Actually for me I didn't quite understand what you were asking, or more to the point what you were attempting to do. I will say that after tinkering with building a complex app using inlined event handlers and passing data around in the HEAP and globals, etc. I found it *much* easier to write my own object wrapper around the Session (or other component) and use the object method handler syntax. Then you can access the data from outside of any session or from within the session itself through the same interface, which made more sense to me personally. This is one area that I would like to see improved in the POE cookbook, as most of the examples (and rightfully so) use the inline state syntax, but I think the object syntax is easier to build on. I have been trying to get my employer to let me release some of my code without much luck, sorry. So essentially you end up with a self contained session as the implementation of a wrapper object. And either creation of the object or calling a particular method on the object init's the session. So I usually end up with the following methods: new, start, stop, pause, resume, shutdown, and then any event handler methods, and other accessors/etc. new instantiates an object, start creates the POE::Session, stop destroys the Session but leaves the object intact (it can be restarted), pause and resume do the same without destroying the session, and shutdown would be similar to a DESTROY. This has proved to be a very clean way of handling lots of different types of sessions working together within a single application.... Not sure if does but HTH, http://danconia.org > Jay > "Jake" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Hi, > > > > I want to write a package which contains my client code. I don't want to > > use globals, to pass data from the server response to my public interface > > but I can't find an example. Roughly here is what I'd like to do, but > don't > > know how: > > > > package MyApp::POEC; > > > > use strict; > > use warnings; > > > > require Exporter; > > our @ISA = qw(Exporter); > > our @EXPORT_OK = qw[quote]; > > > > use POE qw(Component::Client::TCP Filter::Reference); > > > > sub quote { > > my %data; > > > > POE::Component::Client::TCP->new( > > RemoteAddress => "localhost", > > Filter => "POE::Filter::Reference", > > RemotePort => 11111, > > Connected => \&connected, > > ## somehow here at ServerInput pass \%data > > ServerInput => \&serverResponse > > ); > > > > $poe_kernel->run(); > > # > > # Here I'd like to print the stuff passed back by the server > > # like: > > print join(",",map{"$_ = $data{$_}"} keys %data,"\n"; > > > > # I don't know maybe there is some way to pass the stuff inside of the > HEAP > > # but I can't see how I'd get to it at this point of the program > > } > > > > sub connected { > > > > my $heap = $_[HEAP]; > > my $symbol = 'QQQ'; > > $heap->{server}->put(\$symbol); > > } > > > > sub serverResponse { > > > > my ( $kernel, $data) = @_[ KERNEL, ARG0 ]; > > # > > # Here I'd like to pass "$data" back to "quote" (i.e. the caller) > > # > > $kernel->yield("shutdown"); > > } > > > > > > > > > > > >
