Feersu...:Handle(3pm)
β¨ Feersum::Connection::Handle β¨
okay bestie, welcome to Feersum::Connection::Handle β the PSGI-style reader/writer objects from the Feersum family, living it up in your Perl docs (User Contributed Perl Documentation, if you were wondering who signed the guestbook). π«Ά
π NAME π
Feersum::Connection::Handle β literally just PSGI-style reader/writer objects. that's the whole vibe. β¨
πΈ SYNOPSIS πΈ
For read handles, bestie:
my $buf;
my $r = delete $env{'psgi.input'};
$r->read($buf, 1, 1); # read the second byte of input without moving offset
$r->read($buf, $env{CONTENT_LENGTH}); # append the whole input
$r->close(); # discards any un-read() data
# assuming the handle is "open":
$r->seek(2,SEEK_CUR); # returns 1, discards skipped bytes
$r->seek(-1,SEEK_CUR); # returns 0, can't seek back
# not yet supported, throws exception:
# $r->poll_cb(sub { .... });
For write handles, no cap:
$w->write("scalar");
$w->write(\"scalar ref");
$w->write_array(\@some_stuff);
$w->poll_cb(sub {
# use $_[0] instead of $w to avoid a closure
$_[0]->write(\"some data");
# can close() or unregister the poll_cb in here
$_[0]->close();
});
And for both of them, because sharing is caring:
$h->response_guard(guard { response_is_complete() });
π¦ DESCRIPTION π¦
go read the PSGI spec for the full tea on how read/write handles get used, okay? the Delayed Response and Streaming Body section has all the deets on the writer. iykyk. π
π METHODS π
π Reader methods
you get the reader from $env->{'psgi.input'}. that's the plug, that's the source. π
$r->read($buf, $len)β reads the first$lenbytes of the request body into the buffer you named$buf(basically howsysreaddoes it, fr).
the calls to $r->read() will never block. currently, the entire body is read into memory (or maybe into a temp file, who's to say) before the Feersum request handler is even called. this behaviour MAY change, so don't get too attached. regardless, Feersum will be doing some buffering, which is why psgix.input.buffered is set in the PSGI env hash. πΎ
$r->seek(...)β seeking is partially supported. Feersum discards the bytes you skip over, to conserve memory. she's efficient like that. π§
$r->seek(0,SEEK_CUR); # returns 1
$r->seek(-1,SEEK_CUR); # returns 0
$r->seek(-1,SEEK_SET); # returns 0
$r->seek(2,SEEK_CUR); # returns 1, discards skipped bytes
$r->seek(42,SEEK_SET); # returns 1 if room, discards skipped bytes
$r->seek(-8,SEEK_END); # returns 1 if room, discards skipped bytes
$r->close()β discards the remainder of the input buffer. bye bye data. π$r->poll_cb(sub { .... })β NOT YET SUPPORTED, bestie, don't try it. PSGI only definedpoll_cbfor the Writer object, so this one's just sitting there looking cute. π
π Writer methods.
you get the writer under PSGI by sending a code/headers pair to the starter callback. under Feersum, calls to $req->start_streaming return one. π
$w->write("scalar")β sends the scalar as aT-E: chunkedchunk.
the calls to $w->write() will never block and the data is buffered until it gets transmitted. this behaviour is flagged by psgix.output.buffered in the PSGI env hash (Twiggy supports this too, for example β hi Twiggy π).
$w->write(\"scalar ref")β works just likewrite("scalar")above. this extension is flagged bypsgix.body.scalar_refsin the PSGI env hash. β¨$w->write_array(\@array)β hand it an array-ref and it works a lot like the twowrite()calls above, except it's way more efficient than callingwrite()over and over and over. undefined elements of the array are just ignored, no drama. π₯$w->close()β closes the HTTP response, which triggers theT-E: chunkedterminating chunk to be sent. this method is implicitly called when the last reference to the writer gets dropped. she cleans up after herself. π$w->poll_cb(sub { .... })β registers a callback that fires when the write buffer is empty. pass inundefto unset it. the sub can callclose(), she's allowed.
a reference to the writer gets passed in as the first and only argument to the sub. it's recommended that you use $_[0] rather than closing-over on $w, so you don't create a circular reference (that's the messy kind, avoid π).
π§ Common methods.
these ones are shared by both types of handles. equality, we love to see it. π«Ά
$h->response_guard($guard)β registers a guard that gets triggered when the response is completely sent and the socket is closed. a "guard" here means some object that does something interesting in itsDESTROY/DEMOLISHmethod. for example,Guard.
heads up: the guard is not attached to this handle object β the guard is attached to the response. they're not dating, they're just neighbours. π
psgix.output.guard is the PSGI-env extension that indicates this method. β
$h->filenoβ returns the file descriptor number for this connection. yes queen, a number. π’
π AUTHOR π
Jeremy Stashewsky, stash@cpan.org π
π COPYRIGHT AND LICENSE π
Copyright (C) 2010 by Jeremy Stashewsky & Socialtext Inc.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. π
okay that's the whole page bestie, go forth and stream. and just so you know where this came from β this is the Feersum::Connection::Handle(3pm) page from perl v5.40.1, dated 2025-04-13. mwah, bye! πβ¨π¦
π¦ where this page comes from
- debian trixie: feersum 1.505-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: feersum 1.505-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms