Joshua Hoblitt <[EMAIL PROTECTED]> writes: > > 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. > > I had some discussion about this on freenode/#perl before submitting > the patch. Everyone asked why the parts count wasn't returned in > scalar context. :) I had wanted to maintain backwards compatibility > but, now that I think about it, I doubt many are using that method > in scalar context. Why don't you just fix the behavior now?
Because I don't know if anybody is using that method in scalar context and I don't want to break published APIs. It might be unlikely that any code actually breaks, but the benefit of doing this change is also very small. Why isn't parts count returned in scalar context? Because I felt that it would be more useful to not have to force array context when you want to extract the single part of a 'message/*' message if ($res->content_type =~ m,^message/,) { if (my $part = $res->parts) { # do something with the part ... } } and if there was a strong demand for getting the number of parts we could always add a method for that purpose. If I redid this now I think I would make 'parts' return the number and then add a 'part' method (without the 's') that always returns the first part regardless of context. Regards, Gisle