Subject: | Incorrect parsing on sources other than listrefs |
News::Article's read() (and hence its constructor) incorrectly handles scalarref and coderef sources. From a scalarref, frequently only the first header is correctly parsed, the others and the body are blank. From a coderef returning an entire article on the first call and undef thereafter, the headers seem to be parsed correctly, but the body is blank.
Sample code:
use News::Article;
@s =("Subject: sample\n",
"From: foo\@bar.com\n",
"To: sample\@robomoderator.tld\n",
"Message-Id: <foo09238740192\@bar.tld>\n",
"\n",
"Body\nfoo\n");
$s = join('',@s);
# scalarref approach: only first header parses correctly
$a = News::Article->new(\ join('',@s));
print "$_ -> ".$a->header($_)."\n" for ('subject','from','to','message-id');
print "body => ".join("\n",$a->body)."\n---\n";
# subroutine approach: headers parsed correctly, body blank
$r = sub { !$n++ ? $s : undef };
$a = News::Article->new($r );
print "$_ -> ".$a->header($_)."\n" for ('subject','from','to','message-id');
print "body => ".join("\n",$a->body)."\n---\n";
# this works, but seems to be the only way to get a correctly
# parsed News::Article from a scalar:
@c = map { "$_\n" } split(/\n/, $s);
$a = News::Article->new(\ @c);
print "$_ -> ".$a->header($_)."\n" for ('subject','from','to','message-id');
print "body => ".join("\n",$a->body)."\n";