Tangence::Stream(3pm)
β¨ Tangence::Stream β¨
okay bestie, gather round, because we're talking about Tangence::Stream β the 3pm manual page, the moment, the icon π
this is the base class for all the Tangence stream-handling mixins and honestly? she's doing a lot behind the scenes π
πΈ DESCRIPTION πΈ
So this module provides a base for Tangence::Client and Tangence::Server. That's it, that's the job. And listen β it is not intended to be used directly by Tangence implementation code, okay? She's a base, not a main character for everyone to just casually instantiate π
What she actually does is provide the basic layer of message serialisation, deserialisation, and dispatching to the methods that would handle the messages. Higher level classes come along and wrap all this functionality, plus provide the implementations of the methods that handle the messages coming in. She sets the vibe, they do the homework π
When a message arrives, it gets passed to a method whose name depends on the code of the message received. The name will be handle_request_, followed by the name of the message code, in uppercase. So like, for example, handle_request_CALL. The way that naming convention just works? obsessed β¨
π REQUIRED METHODS π
These are the methods that are required to be implemented by some class using this mixin. No skipping, bestie, she needs these π«Ά
tangence_write
$stream->tangence_write( $data );
Write bytes of data to the connected peer. $data will be a plain perl string. Just bytes, just vibes π
handle_request_$CODE
$stream->handle_request_$CODE( $token, $message );
Invoked on receipt of a given message code. $token will be some opaque perl scalar value, and $message will be an instance of Tangence::Message π¦
The value of the token has no particular meaning, other than to be passed to the respond method. She's mysterious, she's just here to be handed along, respect it π
π PROVIDED METHODS π
The following methods are provided by this mixin. Free of charge, on the house, you're welcome π
tangence_closed
$stream->tangence_closed;
Informs the object that the underlying connection has now been closed, and any attachments to Tangence::Object or Tangence::ObjectProxy instances should now be dropped. It's giving closure, literally π
tangence_readfrom
$stream->tangence_readfrom( $buffer );
Informs the object that more data has been read from the underlying connection stream. Whole messages will be removed from the beginning of the $buffer, which should be passed as a direct scalar (because it will be modified β no copies, bestie, she edits in place π).
This method will invoke the required handle_request_* methods. Any bytes remaining that form the start of a partial message will be left in the buffer. She's patient, she'll finish that message next time β
request
$stream->request( %args );
Serialises a message object to pass to the tangence_write method, then enqueues a response handler to be invoked when a reply arrives. Takes the following named arguments:
request => Tangence::Messageβ the message body πon_response => CODEβ aCODEreference to the callback to be invoked when a response to the message is received. It will be passed the response message:
$on_response->( $message );
request (non-void)
$response = await $stream->request( request => $request );
When called in non-void context, this method returns a Future that will yield the response instead π₯ In this case it should not be given an on_response callback β pick a lane, bestie, you can't have both π
ββοΈ
In this form, a MSG_ERROR response will automatically turn into a failed Future; the subsequent then or on_done code will not have to handle this case. She handles the drama so you don't have to π
β¨
respond
$stream->respond( $token, $message );
Serialises a message object to be sent to the tangence_write method. The $token value that was passed to the handle_request_ method ensures that it is sent at the correct position in the stream, to allow the peer to pair it with the corresponding request. Matchmaking, but for messages π
minor_version
$ver = $stream->minor_version;
Returns the minor version negotiated by the MSG_INIT / MSG_INITED initial message handshake. Cute little intro ritual, love that for them π¦
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> β the legend, the blueprint, no cap π
and that's the whole page, bestie!! this was Tangence::Stream(3pm) from the User Contributed Perl Documentation, and this particular copy is from perl v5.40.0, dated 2024-09-13 π stay hydrated, go write your tangence_write, and slay β¨π
π¦ where this page comes from
- ubuntu resolute: libtangence-perl 0.33-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtangence-perl 0.33-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms