1vCard::AddressBook(3) User Contributed Perl DocumentationvCard::AddressBook(3)
2
3
4
6 vCard::AddressBook - Read, write, and edit vCard address books
7
9 use vCard::AddressBook;
10
11 # create the object
12 my $address_book = vCard::AddressBook->new();
13
14 # these methods load vCard formatted data
15 $address_book->load_file('/path/file.vcf');
16 $address_book->load_string($string);
17
18 my $vcard = $address_book->add_vcard; # returns a vCard object
19 $vcard->full_name('Bruce Banner, PhD');
20 $vcard->family_names(['Banner']);
21 $vcard->given_names(['Bruce']);
22 $vcard->email_addresses([
23 { type => ['work'], address => 'bbanner@ssh.secret.army.mil' },
24 { type => ['home'], address => 'bbanner@timewarner.com' },
25 ]);
26
27 # $address_book->vcards() returns an arrayref of vCard objects
28 foreach my $vcard (@{ $address_book->vcards() }) {
29 print $vcard->full_name() . "\n";
30 print $vcard->email_addresses->[0]->{address} . "\n";
31 }
32
33 # these methods output data in vCard format
34 my $file = $address_book->as_file('/path/file.vcf'); # write to a file
35 my $string = $address_book->as_string();
36
38 A vCard is a digital business card. vCard and vCard::AddressBook
39 provide an API for parsing, editing, and creating vCards.
40
41 This module is built on top of Text::vCard and Text::vCard::AddressBook
42 and provides a more intuitive user interface.
43
45 Constructor Arguments
46 The 'encoding_in' and 'encoding_out' constructor parameters allow you
47 to read and write vCard files with any encoding. Examples of valid
48 values are 'UTF-8', 'Latin1', and 'none'.
49
50 Both parameters default to 'UTF-8' and this should just work for the
51 vast majority of people. The latest vCard RFC 6350 only allows UTF-8
52 as an encoding so most people should not need to use either parameter.
53
54 MIME encodings
55 vCard RFC 6350 only allows UTF-8 but it still permits 8bit MIME
56 encoding schemes such as Quoted-Printable and Base64 which are
57 supported by this module.
58
59 Getting and setting values on a vCard object
60 If you set values on a vCard object they must be decoded values. The
61 only exception to this rule is if you are messing around with the
62 'encoding_out' constructor arg.
63
64 When you get values from a vCard object they will be decoded values.
65
67 add_vcard()
68 Creates a new vCard object and adds it to the address book. Returns a
69 vCard object.
70
71 load_file($filename)
72 Load and parse the contents of $filename. Returns $self so the method
73 can be chained.
74
75 load_string($string)
76 Load and parse the contents of $string. This method assumes that
77 $string is decoded (but not MIME decoded). Returns $self so the method
78 can be chained.
79
80 as_file($filename)
81 Write all the vCards to $filename. Files are written as UTF-8 by
82 default. Dies if not successful.
83
84 as_string()
85 Returns all the vCards as a single string.
86
88 Eric Johnson (kablamo), github ~!at!~ iijo dot org
89
91 Thanks to Foxtons <http://foxtons.co.uk> for making this module
92 possible by donating a significant amount of developer time.
93
94
95
96perl v5.32.0 2020-07-28 vCard::AddressBook(3)