Net::MQTT::Message(3)
π Net::MQTT::Message β the Perl module that's literally your MQTT bestie π
Okay so bestie, welcome to Net::MQTT::Message(3) β the User Contributed Perl Documentation page for a module that lowkey does one thing and does it iconically: it wraps up a single MQTT message so you can ship it to a socket or scoop one back out. Slay. β¨
πΈ VERSION πΈ
version 1.163170 β no cap, that's the one.
π¦ SYNOPSIS π¦
So like, here's how you actually use it. Copy it exactly, don't @ me:
use Net::MQTT::Constants;
use Net::MQTT::Message;
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(PeerAddr => '127.0.0.1:1883');
my $mqtt = Net::MQTT::Message->new(message_type => MQTT_CONNECT);
print $socket $mqtt->bytes;
my $tcp_payload = pack 'H*', '300d000774657374696e6774657374';
$mqtt = Net::MQTT::Message->new_from_bytes($tcp_payload);
print 'Received: ', $mqtt->string, "\n";
π«Ά See? Beautiful. Build a message, yeet it at the socket, then parse one back and print a little summary like the main character you are.
β¨ DESCRIPTION β¨
This module encapsulates a single MQTT message β like, one (1) vibe, one (1) packet. It's got subclasses that each represent a specific message type, because apparently we're doing object-oriented gatekeeping and honestly? It works. π
π METHODS π
new( %parameters ) β the constructor, the moment, the icon
Constructs a Net::MQTT::Message object from the parameters you hand it. The common parameter keys are:
message_typeβ the message type field of the MQTT message. This should be an integer between0and15inclusive. The moduleNet::MQTT::Constantsprovides constants you can use for this value. π This parameter is required. (Fr, you cannot skip it.)dupβ the duplicate flag field of the MQTT message. Should be either1or0. The default is0.qosβ the QoS field of the MQTT message. Should be an integer between0and3inclusive. The default is as specified in the spec or0("at most once") otherwise. The moduleNet::MQTT::Constantsprovides constants you can use for this value.retainβ the retain flag field of the MQTT message. Should be either1or0. The default is0.
The remaining keys are dependent on the specific message type. π§ The documentation for the subclasses for each message type lists methods with the same name as the required keys.
new_from_bytes( $packed_bytes, [ $splice ] ) β glow-up from raw bytes
Attempts to construct a Net::MQTT::Message object based on the given packed byte string. If there are insufficient bytes, then undef is returned. π (Rude but fair.)
If the splice parameter is provided and true, then the processed bytes are removed from the scalar referenced by the $packed_bytes parameter. π Very efficient, very mindful.
message_type() β what's your type, bestie?
Returns the message type field of the MQTT message. The module Net::MQTT::Constants provides a function, message_type_string, that can be used to convert this value to a human-readable string. π
dup() β the duplicate flag, no more no less
The duplicate flag field of the MQTT message.
qos() β quality of service, quality of life
The QoS field of the MQTT message. The module Net::MQTT::Constants provides a function, qos_string, that can be used to convert this value to a human-readable string. π
retain() β keep it, queen
The retain field of the MQTT message.
remaining() β the leftover crumbs π
This contains a packed string of bytes with any of the payload of the MQTT message that was not parsed by these modules. This should not be required for packets that strictly follow the standard.
string([ $prefix ]) β the logging summarize moment
Returns a summary of the message as a string, suitable for logging. If provided, each line will be prefixed by the optional $prefix. So cute, so organized. π
bytes() β the actual raw material
Returns the bytes of the message, suitable for writing to a socket. Slap it into your print $socket ... and go. π₯
π AUTHOR π
Mark Hindess <soft-cpan@temporalanomaly.com> β the mastermind, the moment.
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2014 by Mark Hindess.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Okay bestie, that's the whole page β every flag, every method, every default, every name, all intact. π«Ά This was perl v5.42.2 and the page date is 2026-02-15 β so like, mark your calendars and go write some MQTT messages. You're gonna slay. πβ¨π
π¦ where this page comes from
- alpine 3.24: perl-net-mqtt-doc 1.163170-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms