The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
Changes 010
META.yml 11
lib/Text/vCard/Addressbook.pm 017
lib/Text/vCard.pm 22
t/05-export.t 117
t/apple_2.1_unicode.vcf 99
t/apple_version3.vcf 1111
t/notes.vcf 1313
8 files changed (This is a version diff) 3780
@@ -1,5 +1,15 @@
 Revision history for Perl extension Text::vCard.
 
+2.09 Thu 19 Aug 2010 16:08:20 BST
+    - Add set_encoding() for export - Stefan
+
+2.08 Tue Jul 13 08:47:58 BST 2010
+    - Doc fix (Blair Christensen)
+
+2.07 Wed 28 Jan 2010 22:16:05 GMT
+    - Fix bug in get_simple_type() (Philip A. Prindeville)
+    - Simplify Makefile.PL and deprecate unused fields (Philip A. Prindeville)
+
 2.06 Sun 24 Jan 2010 10:02:01 GMT
     - Doc typos (Philip A. Prindeville)
     - Add get_simple_type() and import_data() (Philip A. Prindeville)
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Text-vCard
-version:            2.07
+version:            2.09
 abstract:           Module for parsing and creating vCards (RFC 2426) address
 author:
     - Leo Lapworth
@@ -161,6 +161,22 @@ sub vcards {
     return wantarray ? @{ $self->{cards} } : $self->{cards};
 }
 
+=head2 set_encoding()
+
+  $address_book->add_vcard('utf-8');
+
+This method will add the string ';charset=utf-8' to each and 
+every vCard entry. That does help in connection with e.g. an iPhone...
+
+=cut
+
+sub set_encoding{
+	my ( $self, $coding) = @_;
+	$self->{'encoding'} |= '';
+	$self->{'encoding'} = ";charset=$coding" if ( defined $coding);
+	return $self->{'encoding'};
+}
+
 =head2 export()
 
   my $vcf_file = $address_book->export()
@@ -195,6 +211,7 @@ sub export {
 
                 my $param;
                 $param = join( ',', ( $node->types() ) ) if $node->types();
+                $name .= $self->set_encoding();
                 $name .= ";TYPE=$param" if $param;
                 push( @lines, "$name:" . $node->export_data );
             }
@@ -10,7 +10,7 @@ use Text::vCard::Node;
 # See this module for your basic parser functions
 use base qw(Text::vFile::asData);
 use vars qw ($VERSION %lookup %node_aliases @simple);
-$VERSION = '2.07';
+$VERSION = '2.09';
 
 # If the node's data does not break down use this
 my @default_field = qw(value);
@@ -568,7 +568,7 @@ it and/or modify it under the same terms as Perl itself.
 
 =head1 SEE ALSO
 
-Text::vCard::Address, Text::vCard::Node
+Text::vCard::Addressbook, Text::vCard::Node
 
 =cut
 
@@ -4,7 +4,7 @@ use strict;
 
 use lib qw(./lib);
 
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 use Data::Dumper;
 # Check we can load module
@@ -40,6 +40,22 @@ my @lines = split("\r\n",$vcf);
 is($lines[0],'BEGIN:VCARD','export() - First line correct');
 is($lines[$#lines],'END:VCARD','export() - Last line correct');
 
+$adbk->set_encoding('utf-8');
+@data = (
+	'BEGIN:VCARD',
+	'item1.X-ABADR;charset=utf-8:uk',
+	'item2.X-ABADR;charset=utf-8:uk',
+	'N;charset=utf-8:T-surname;T-first;;;',
+	'TEL;charset=utf-8;TYPE=pref,home:020 666 6666',
+	'TEL;charset=utf-8;TYPE=cell:0777 777 7777',
+	'item2.ADR;charset=utf-8;TYPE=work:;;Test Road;Test City;;Test Postcode;Test Country',
+	'item1.ADR;charset=utf-8;TYPE=pref,home:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country',
+	'VERSION;charset=utf-8:3.0',
+	'FN;charset=utf-8:T-firstname T-surname',
+	'END:VCARD',
+);
+@lines = split ( "\r\n" , $adbk->export());
+is_deeply(\@lines,\@data,'set_encoding() - returned data matched that expected');
 #is_deeply(\@lines,\@data,'export() - returned data matched that expected');
 
 #my $notes = Text::vCard::Addressbook->new({ 'source_file' => 't/notes.vcf'});
@@ -1,9 +1,9 @@
-BEGIN:VCARD
-VERSION:2.1
-N:T-surname;T-first;;;
-FN:T-firstname T-surname
-TEL;HOME:020 666 6666
-TEL;CELL:0777 - 777 7777
-ADR;HOME:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country
-ADR;WORK:;;Test Road;Test City;;Test Postcode;Test Country
-END:VCARD
+BEGIN:VCARD
+VERSION:2.1
+N:T-surname;T-first;;;
+FN:T-firstname T-surname
+TEL;HOME:020 666 6666
+TEL;CELL:0777 - 777 7777
+ADR;HOME:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country
+ADR;WORK:;;Test Road;Test City;;Test Postcode;Test Country
+END:VCARD
@@ -1,11 +1,11 @@
-BEGIN:VCARD
-VERSION:3.0
-N:T-surname;T-first;;;
-FN:T-firstname T-surname
-TEL;type=HOME;type=pref:020 666 6666
-TEL;CELL:0777 777 7777
-item1.ADR;type=HOME;type=pref:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country
-item1.X-ABADR:uk
-item2.ADR;type=WORK:;;Test Road;Test City;;Test Postcode;Test Country
-item2.X-ABADR:uk
-END:VCARD
+BEGIN:VCARD
+VERSION:3.0
+N:T-surname;T-first;;;
+FN:T-firstname T-surname
+TEL;type=HOME;type=pref:020 666 6666
+TEL;CELL:0777 777 7777
+item1.ADR;type=HOME;type=pref:;;Pref Test Road;Pref Test City;;Pref Test Postcode;Pref Test Country
+item1.X-ABADR:uk
+item2.ADR;type=WORK:;;Test Road;Test City;;Test Postcode;Test Country
+item2.X-ABADR:uk
+END:VCARD
@@ -1,13 +1,13 @@
-BEGIN:VCARD
-VERSION:3.0
-N:;;;;
-FN:Test
-ORG:Test;
-TEL;type=WORK;type=pref:123/1234123
-item1.ADR;type=WORK;type=pref:;;12a The Street.;Montreal;Quebec;;Canada
-item1.X-ABADR:ca
-NOTE:@prefix nasty <note>\; with \; added into it and\n@prefix del: \n"\; ]]\;\n]\;\n.
-X-ABShowAs:COMPANY
-CATEGORY:montreal
-END:VCARD
-
+BEGIN:VCARD
+VERSION:3.0
+N:;;;;
+FN:Test
+ORG:Test;
+TEL;type=WORK;type=pref:123/1234123
+item1.ADR;type=WORK;type=pref:;;12a The Street.;Montreal;Quebec;;Canada
+item1.X-ABADR:ca
+NOTE:@prefix nasty <note>\; with \; added into it and\n@prefix del: \n"\; ]]\;\n]\;\n.
+X-ABShowAs:COMPANY
+CATEGORY:montreal
+END:VCARD
+