Gisle Aas <[EMAIL PROTECTED]> writes:

> Thinking some more.  This is what I think I would like to see.

The just released libwww-perl-5.77 contains the HTTP::MessageParts
module that implements this.  It is still experimental and it lacks
documentation.  Loading the HTTP::MessageParts module will populate
the HTTP::Message class with the parts() and add_part() methods.
Check it out and tell me if it works for you.

> We introduce the methods 'parent', 'parts' and 'add_part' to
> HTTP::Message.
>   $msg2 = $msg->parent
>     This attribute point back to the parent message.  If defined
>     it makes this message a message part belonging to the parent
>     message.  This attribute is set by the other methods described
>     below.
>     We might consider automatic delegation to the parent, but
>     I'm not sure how useful that would be.

I did not implement this method as there is no obvious way to avoid
the circular reference in this case.  I'll revise this decision if a
strong use case for this method can be shown.

>   @parts = $msg->parts
>     This will return a list of HTTP::Message objects.  If the
>     content-type of $msg is not multipart/* or message/* then this
>     will return the empty list.  The returned message part objects
>     are read only (so that future versions can make it possible to
>     modify the parent by modifying the parts).
>     If the content-type of $msg is message/* then there will only
>     be one part.
>     If the content-type is message/http, then this will return either
>     an HTTP::Request or an HTTP::Response object.

All of this should work.

>   $msg->parts( @parts )
>   $msg->parts( [EMAIL PROTECTED] )

Only the first form has been implemented.

>     This will set the content of the message to be the provided list
>     of parts.  If the old content-type is not multipart/* or message/*
>     then it is set to multipart/mixed and other content-* headers are
>     cleared as well.  The part objects now belong to $msg and can not
>     be set to be parts of other messages, but clones can be made part
>     of other messages.  This method will croak if the provided parts
>     are not independent.
>     This method will croak if the content type is message/* and more
>     than one part is provided.
>     The array ref form is provided so that an empty list can be
>     provided without any special cases.

Not all this semantic is implemented yet.

>   $msg->add_part( $part )
>     This will add a part to a message.  If the old content-type is not
>     multipart/* then the old content (together with all content-*
>     headers) will be made part #1 and the content-type made
>     multipart/mixed before the new part is added.

Not yet implemented.

>   $part->clone
>     Will return an independent part object (i.e. the parent
>     attribute will always be cleared).  This ensures that
>     this works:
>         $msg2->parts([map $_->clone, $msg1->parts]);

Behaviour change not needed since $msg->parent is not there.


Reply via email to