DIME::Tools(3pm)

✨ DIME::Tools β€” the manual page, but make it cute ✨

okay so bestie, welcome to DIME::Tools, a Perl module (that's a 3pm manual page, user-contributed docs, iykyk) πŸ’– it's the whole vibe of parsing and generating DIME messages. strap in πŸŽ€


🌸 NAME 🌸

DIME::Tools β€” modules for parsing and generate DIME messages ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

πŸ’œ Generating DIME messages

my $payload = DIME::Payload->new();
$payload->attach(Path => "/mydata/index.html",
                 MIMEType => 'text/html',
                 Dynamic => 1);

my $payload2 = DIME::Payload->new();
$payload2->attach( Data => "HELLO WORLD!!!",
                   MIMEType => 'text/plain' );

my $message = DIME::Message->new();

my $payload = DIME::Payload->new();
$payload->attach(Path => "/mydata/index.html",
                 MIMEType => 'text/html',
                 Dynamic => 1);

$message->add_payload($payload);
$message->add_payload($payload2);

# Print the encoded message to STDOUT
$message->print(\*STDOUT);

🌈 Parsing DIME messages

my $parser = DIME::Parser->new();

# Open a file with a dime encoded message
$f = IO::File->new("dime.message","r");
my $message = $parser->parse($f);
$f->close();

# Print the content of each payload to STDOUT
for my $i ($message->payloads())
{
        print $i->print_content(\*STDOUT);
}

🌟 DESCRIPTION 🌟

DIME-tools is a lil collection of DIME:: modules for parsing and generating DIME encoded messages β€” that's Direct Internet Message Encapsulation, for the uninitiated πŸ’… DIME-tools supports single-record and chunked payloads, so you can send big attachments without it being a whole thing. slay.

fr fr, this distribution hasn't been actively developed since 2004 😭 the releases after that have just been to get it following CPAN conventions, because there's exactly one distribution depending on it. so like... it's iconic, but it's resting. 🫢

πŸŽ€ GENERATING MESSAGES πŸŽ€

For any content you wanna send in a message, you gotta create a Payload object first:

my $payload = DIME::Payload->new();
$payload->attach(Path => "/mydata/index.html",
                 MIMEType => 'text/html',
                 Dynamic => 1);

With the attach method you can specify these keys πŸ‘‡

  • Path β€” the name of the file you wanna attach to the payload object. if the data you wanna attach isn't in a file, you can use the Data key instead πŸ’–
  • Data β€” it's the reference to a scalar where you store the data you wanna attach.
  • Dynamic β€” if Path is declared, the data is not loaded fully into memory. the only thing you attach to the payload object is the name of the file from the Path key, not the content itself. lowkey efficient, highkey iconic ✨
  • Chunked β€” if it's declared, it represents the size of the chunk records in bytes. if you don't declare it, the message will not be chunked. periodt.
  • MIMEType β€” the type of the payload. it has to be a string with a MIME standard type. the other option is to use URIType.
  • URIType β€” specifies a URI that defines that type of the content.

🫢 ATTACH A PAYLOAD TO A MESSAGE 🫢

my $message = DIME::Message->new();
$message->add_payload($payload);

# Print prints to any IO::Handle
$message->print(\*STDOUT);

or

# print_data returns a reference to a scalar
print ${$message->print_data()};

πŸ”₯ PARSING MESSAGES πŸ”₯

All you gotta do is create a DIME::Parser object and call the parse method with an IO::Handle pointing at a DIME message. then you can iterate over the $message->payloads() array to get the contents of the message:

my $parser = DIME::Parser->new();
$f = IO::File->new("dime.message","r");
my $message = $parser->parse($f);
$f->close();
for my $i ($message->payloads())
{
        print $i->print_content(\*STDOUTs);
}

You can also call parse_data if you have a DIME message sitting in a scalar variable:

my $dime_message;
my $message = $parser->parse_data(\$dime_message);

And call print_content_data if what you want is to get a reference to the content-data. πŸ’œ


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’– AUTHOR πŸ’–

Domingo Alcazar Larrea, <dalcazar@cpan.org> 🌸


Copyright (C) 2004 Domingo AlcΓ‘zar Larrea

This program is free software; you can redistribute it and/or modify it under the terms of the version 2 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307


okay that's the whole thing bestie, no notes πŸ’€βœ¨ this was perl v5.32.1, dated 2021-03-22 β€” so go forth and parse, and remember: single-record and chunked payloads both ate, and they left no crumbs πŸŽ€πŸ¦‹ bye ily πŸ’–