Data-ICal
view release on metacpan or search on metacpan
lib/Data/ICal/Property.pm view on Meta::CPAN
=head1 DESCRIPTION
A L<Data::ICal::Property> object represents a single property on an
entry in an iCalendar file. Properties have parameters in addition to
their value.
You shouldn't need to create L<Data::ICal::Property> values directly
-- just use 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<encode> methods: all other methods
access the encoded version directly (if there is an encoding).
Currently, the only supported encoding is C<QUOTED-PRINTABLE>.
=head1 METHODS
=cut
=head2 new $key, $value, [$parameter_hash]
lib/Data/ICal/Property.pm view on Meta::CPAN
return MIME::QuotedPrint::encode( $dec, '' );
},
decode => sub {
my $dec = MIME::QuotedPrint::decode( shift || '' );
$dec =~ s/\r\n/\n/g;
return $dec;
}
},
);
=head2 decoded_value
Gets the value of this property, converted from the encoding specified
in its encoding parameter. (That is, C<value> will return the encoded
version; this will apply the encoding.) If the encoding is not
specified or recognized, just returns the raw value.
=cut
sub decoded_value {
my $self = shift;
my $value = $self->value;
my $encoding = uc( $self->parameters->{'ENCODING'} || "" );
if ( $ENCODINGS{$encoding} ) {
return $ENCODINGS{$encoding}{'decode'}->($value);
} else {
return $value;
}
}
=head2 encode $encoding
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 encode {
my $self = shift;
my $encoding = uc shift;
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;
}
return $self;
}
=head2 as_string ARGS
Returns the property formatted as a string (including trailing
newline).
t/09.mime.t view on Meta::CPAN
BEGIN:VCALENDAR
VERSION:2.0
PRODID:Data::ICal @{[$Data::ICal::VERSION]}
BEGIN:VTODO
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
my $decoded_desc = <<'END_DESC';
interesting things
Yeah!!= cbla
Go team syncml!
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( crlf => "\n" ), $encoded_vcal);
t/10.mime-vcal10.t view on Meta::CPAN
my $encoded_vcal_out = <<END_VCAL;
BEGIN:VCALENDAR
VERSION:1.0
PRODID:Data::ICal @{[$Data::ICal::VERSION]}
BEGIN:VTODO
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
my $decoded_desc = <<'END_DESC';
interesting things
Yeah!!= cbla
Go team syncml!
END_DESC
BEGIN { use_ok('Data::ICal') }
my $cal = Data::ICal->new(data => $encoded_vcal_in, vcal10 => 1);
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' }
$cal = Data::ICal->new(vcal10 => 1);
isa_ok($cal, 'Data::ICal');
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($cal->as_string( crlf => "\n"), $encoded_vcal_out);
__END__
possibly useful later
DESCRIPTION;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:interesting thi=
ngs =0D=0A=
Yeah!!=3D =C3=AAtre=0D=0A=
( run in 0.274 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )