Add node CATEGORIES to vcard with perl module "vCard::AddressBook"

80 Views Asked by At

I do not find a possibility to add nodes like CATEGORIES or ORG to a vcard object when using the perl module vCard::AddressBook (https://metacpan.org/pod/vCard::AddressBook).

The output should look like this:

BEGIN:VCARD
VERSION:4.0
...
N:Doe;John;;;
...
ORG:Organization_01;
CATEGORIES:Cat_01
...
END:VCARD

When I use the following code:

use vCard::AddressBook;
my $address_book = vCard::AddressBook->new();
my $vcard = $address_book->add_vcard;
$vcard->given_names(['John']);
$vcard->family_names(['Doe']);
$vcard->categories(['Cat_01']);  ## DOES NOT WORK
my $file = $address_book->as_file('file.vcf');

I get the following error:

Can't locate object method "categories" via package "vCard" at tmp2.pl line 6.

What is the best way to get other nodes like CATEGORIES in my vcard file?

BTW: RFC6350 defines it... https://www.rfc-editor.org/rfc/rfc6350#section-6.7.1

1

There are 1 best solutions below

0
clamp On

There is https://metacpan.org/pod/Text::vCard::Precisely which seems to be more compliant with RFC6350:

use Text::vCard::Precisely;
my $vcard = Text::vCard::Precisely->new( version => '4.0' );
$vcard->n(['John','Doe']);
$vcard->categories([qw/Cat_01 Cat_02 Cat_03/]);
print $vcard->as_string();

prints:

BEGIN:VCARD
VERSION:4.0
N:John;Doe;;;
CATEGORIES:Cat_01,Cat_02,Cat_03
END:VCARD