SYNOPSIS

        Generating DIME messages
        ========================

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

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

                my $message = new DIME::Message;

                my $payload = new DIME::Payload;
                $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 = new DIME::Parser();

                # Open a file with a dime encoded message
                $f = new IO::File("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 collection of \s-1DIME::\s0 modules for parse and generate \s-1DIME\s0 encoded messages ( Direct Internet Message Encapsulation ). DIME-tools support single-record and chunked payloads for sending big attachments.

GENERATING MESSAGES

For any content you want to send in a message, you have to create a Payload object:

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

With the attach method you can specify the next keys:

Path: the name of the file you want to attach to the payload object. If the data you want to attach isn't in a file, you can use the Data key.

Data: it's the reference to a scalar in which you store the data you want to attach.

Dynamic: if Path is declared, the data is not loaded fully in memory. The only that you attach to the payload object is the name of the file of the Path key, not the content itself.

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.

MIMEType: the type of the payload. It must be a string with a MIME standard type. Other possibility is to use URIType.

URIType: specifies an URI that defines that type of the content.

ATTACH A PAYLOAD TO A MESSAGE

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

PRINT A ENCODED MESSAGE

# 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 have to do is create a DIME::Parser object and call the parse method with a IO::Handle to a \s-1DIME\s0 message. Then you can iterate over the $message->payloads() array to get the contents of the message:

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

You can also call to parse_data if you have a \s-1DIME\s0 message 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.

RELATED TO DIME::Tools…

Direct Internet Message Encapsulation draft: http://www.gotdotnet.com/team/xml_wsspecs/dime/dime.htm

DIME::Message DIME::Payload DIME::Record

AUTHOR

Domingo Alcazar Larrea, <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2004 Domingo Alca\*'zar Larrea

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

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

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