ranguard / text-vcard

Perl package to edit and create vCard(s) (RFC 2426)
22 stars 15 forks source link

Catch missing N better #50

Open jidanni opened 7 years ago

jidanni commented 7 years ago

One will get

Can't call method "family" on an undefined value at /usr/share/perl5/vCard/AddressBook.pm line 208, <> line 1686. unless there is a "N" line.

(A workaround is:)

use vCard::AddressBook;
my $address_book = vCard::AddressBook->new();
my ( $I, $J );

while (<>) {
    s/$/\r/ unless /\r$/;
    $I .= $_;
    next unless /END:VCARD/;
    for ('FN', 'N') {
        if ( $I !~ /^$_\W/m ) {
            $I =~ s/^END:VCARD/$_:\r\n$&/m;
        }
    }
    $J .= $I;
    undef $I;
}
$address_book->load_string($J);

Actually a quick reading of the RFCs says that it is a FN, not an N that is required. So above I inject both.

Anyways the program should say "missing N!", "N should be present." etc.