Joshua Hoblitt <[EMAIL PROTECTED]> writes: > After writing this bit of ugly code... > > if ( $res->can( 'parts' ) ) { > die "multipart messages are not supported" unless scalar @{[ $res->parts ]} <= 1; > } > > I decided that an is_multipart method might be handy. Would anyone > else find this functionality useful?
I don't really like it. I would have expected a method like $res->is_multipart to actually test for $res->content_type =~ m,^multipart/,. Seems like I should have made 'parts' return the number of parts in scalar context instead of the first one. That would be more useful here. To stay compatible it seems like the best route is to add a method called 'num_parts', but it is not clear to me why you want to handle multipart messages with one part but not those with more. If the need for testing the number of parts is not a common use case I think it is better to leave this method out. Another approach for you is to simply put this sub into your app: sub HTTP::Message::have_many_parts { my $self = shift; return 0 unless $self->can('parts'); return @{[ $self->parts ]} >= 1; } and then you can write: die "multipart messages are not supported" if $res->have_many_parts; Regards, Gisle