On Wed, Apr 03, 2002 at 12:40:59PM -0500, Al Tobey wrote: > Has anybody written a Filter that passes lines of I/O through > URI::Escape? Currently, I'm doing it manually on each call i.e. > $wheel->put( uri_escape($buffer) ); or $buffer = uri_unescape($buffer);, > but it'd be sweet if there was a POE::Filter that wrapped it all up. > I've looked at writing one, but I'm under a tight schedule right now. > If there is enough interest and nobody else wants to write it, I'll hack > at it in a couple/few weeks. > > The main drive for this is that I'm using POE::Filter::Line to pass data > between a controller and a slave on different hosts and I want to > encapsulate arbitrary data into a single line or "packet" and not have > to do any special delimitation. URI::Escape takes care of most cases > for me (mostly newlines and whitespace). Anyways, I've got most of the > ugliness wrapped up in nice events so the URI:: stuff isn't exposed all > over the place, but I think it'd be an appropriate Filter. > > Any thoughts, ideas?
If you have Perl on both sides of the socket, take a look at POE::Filter::Reference (comes with POE). It will allow you to send arbitrary Perl data structures across filehandles, freezing references on the sender's side and thawing them back into usable data structures at the receiving end. If you have non-perl on the other end, POE::Filter::Reference will let you plug in different serializers. I understand YAML (www.yaml.org) is language-neutral, and it should combine very easily with the Reference filter. On the other other hand, if URI::Escape will work best for your purposes, a filter should be very easy. The Filter::Line class is fairly complex (it includes newline autodetection code), but Filter::Stream makes a simple base for others. Filter::Stackable lets you stack other filters, and Filter::Map lets you perform arbitrary transformations on packets that flow through filter stacks. They can be tricky to use, but you can use them to quickly prototype filters without writing entire classes for them. -- Rocco
