Subject: | MP3::Tag::ID3v2->add_frame always calls Encode::encode on provided strings |
Date: | Fri, 12 Nov 2010 13:03:52 +0100 |
To: | bug-MP3-Tag [...] rt.cpan.org |
From: | Andrey Voropaev <voropaev.andrey [...] googlemail.com> |
I understand, that writing of v2.4 tags is "not supported", but there is code
for this in the module and it does pretty good work for me. There's only one
catch. The code assumes that the text string passed to the method add_frame
has UTF8 flag set, so it calls Encode::encode to convert it into "octets". In
reality, the string might be the "octets" already. So it makes sense to call
Encode::is_utf8 before calling Encode::encode. See the attached patch for
proposed solution.
Actually, it looks like the Encode module is incorrectly used. The function
"decode" converts into internal format assuming that the sequence of given
octets corresponds to specified encoding. The function "encode" converts from
internal format into sequence of octets using specified encoding. There's also
function "from_to" which converts sequence of octets from one encoding into
another encoding. So, the "from_to" function can be viewed as
sub from_to
{
my $new_encoding = pop;
my $old_encoding = pop;
my $t = decode($old_encoding, $_[0]);
$_[0] = encode($new_encoding, $t);
}
Best regards
Andrei Voropaev
Message body is not shown because sender requested not to inline it.