[Rt-commit] r4465 - in Data-ICal: . lib/Data/ICal
glasser at bestpractical.com
glasser at bestpractical.com
Thu Feb 2 23:56:45 EST 2006
Author: glasser
Date: Thu Feb 2 23:56:44 2006
New Revision: 4465
Modified:
Data-ICal/ (props changed)
Data-ICal/lib/Data/ICal/Property.pm
Data-ICal/t/09.mime.t
Log:
r53591 at tin-foil: glasser | 2006-02-02 23:50:11 -0500
Slightly saner way of dealing with changing encodings. (Still doesn't deal with vCal/iCal quirks.)
Modified: Data-ICal/lib/Data/ICal/Property.pm
==============================================================================
--- Data-ICal/lib/Data/ICal/Property.pm (original)
+++ Data-ICal/lib/Data/ICal/Property.pm Thu Feb 2 23:56:44 2006
@@ -24,7 +24,7 @@
C<add_property> in L<Data::ICal::Entry>.
The C<encoding> parameter value is only interpreted by L<Data::ICal> in the
-C<decoded_value> and C<set_value_with_encoding> methods: all other methods access
+C<decoded_value> and C<encode> methods: all other methods access
the encoded version directly (if there is an encoding).
Currently, the only supported encoding is C<QUOTED-PRINTABLE>.
@@ -91,8 +91,17 @@
}
my %ENCODINGS = (
- 'QUOTED-PRINTABLE' => { encode => \&MIME::QuotedPrint::encode,
- decode => \&MIME::QuotedPrint::decode },
+ 'QUOTED-PRINTABLE' => { encode => sub {
+ my $dec = shift;
+ $dec =~ s/\n/\r\n/g;
+ return MIME::QuotedPrint::encode($dec, '');
+ },
+ decode => sub {
+ my $dec = MIME::QuotedPrint::decode(shift);
+ $dec =~ s/\r\n/\n/g;
+ return $dec;
+ }
+ },
);
=head2 decoded_value
@@ -116,20 +125,27 @@
}
}
-=head2 set_value_with_encoding $decoded_value, $encoding
+=head2 encode $encoding
-Encodes C<$decoded_value> in the encoding C<$encoding>; sets the value to the encoded
-value and the encoding parameter to C<$encoding>. Does nothing if the encoding is not
-recognized.
+Calls C<decoded_value> to get the current decoded value, then encodes it in C<$encoding>,
+sets the value to that, and sets the encoding parameter to C<$encoding>. (C<$encoding> is
+first converted to upper case.)
+
+If C<$encoding> is undef, deletes the encoding parameter and sets the value to the decoded
+value. Does nothing if the encoding is not recognized.
=cut
-sub set_value_with_encoding {
+sub encode {
my $self = shift;
- my $decoded_value = shift;
my $encoding = uc shift;
- if ($ENCODINGS{$encoding}) {
+ my $decoded_value = $self->decoded_value;
+
+ if (not defined $encoding) {
+ $self->value($decoded_value);
+ delete $self->parameters->{'ENCODING'};
+ } elsif ($ENCODINGS{$encoding}) {
$self->value( $ENCODINGS{$encoding}{'encode'}->($decoded_value) );
$self->parameters->{'ENCODING'} = $encoding;
}
Modified: Data-ICal/t/09.mime.t
==============================================================================
--- Data-ICal/t/09.mime.t (original)
+++ Data-ICal/t/09.mime.t Thu Feb 2 23:56:44 2006
@@ -3,35 +3,54 @@
use warnings;
use strict;
-use Test::More tests => 4;
+use Test::More tests => 6;
use Test::LongString;
use Test::NoWarnings;
-BEGIN { use_ok('Data::ICal') }
-
-my $cal = Data::ICal->new(data => <<'END_VCAL');
+my $encoded_vcal = <<'END_VCAL';
BEGIN:VCALENDAR
+PRODID:Data::ICal 0.07
+VERSION:2.0
BEGIN:VTODO
-DESCRIPTION;ENCODING=QUOTED-PRINTABLE:interesting things =0D=0A
- Yeah!!=3D =63bla=0D=0A=0D=0A=0D=0AGo team syncml!=0D=0A=0D=0A=0D=0A
+DESCRIPTION;ENCODING=QUOTED-PRINTABLE:interesting things =0D=0AYeah
+ !!=3D cbla=0D=0A=0D=0A=0D=0AGo team syncml!=0D=0A=0D=0A=0D=0A
END:VTODO
END:VCALENDAR
END_VCAL
-isa_ok($cal, 'Data::ICal');
+my $decoded_desc = <<'END_DESC';
+interesting things
+Yeah!!= cbla
+
+
+Go team syncml!
+
-is_string($cal->entries->[0]->property("description")->[0]->decoded_value, <<"END_DESC");
-interesting things \r
-Yeah!!= cbla\r
-\r
-\r
-Go team syncml!\r
-\r
-\r
END_DESC
+BEGIN { use_ok('Data::ICal') }
+
+my $cal = Data::ICal->new(data => $encoded_vcal);
+
+isa_ok($cal, 'Data::ICal');
+
+is_string($cal->entries->[0]->property("description")->[0]->decoded_value, $decoded_desc);
+
+$cal = Data::ICal->new;
+
+BEGIN { use_ok 'Data::ICal::Entry::Todo' }
+
+my $todo = Data::ICal::Entry::Todo->new;
+$cal->add_entry($todo);
+
+$todo->add_property(description => $decoded_desc);
+
+$cal->entries->[0]->property('description')->[0]->encode('QUotED-PRintabLE');
+is_string($cal->as_string, $encoded_vcal);
+
__END__
+possibly useful later
DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:interesting thi=
ngs =0D=0A=
Yeah!!=3D =C3=AAtre=0D=0A=
More information about the Rt-commit
mailing list