ranguard / text-vcard

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

Undefined value at line 208 #39

Open hrossmvn opened 8 years ago

hrossmvn commented 8 years ago

Sorry, my Perl isn't good enough to fix this myself....

The full error text is 'Can't call method "family" on an undefined value at C:/Strawberry/perl/site/lib/vCard/AddressBook.pm line 208

This happens with 2 different address books downloaded from my webmail and a colleagues webmail. I have made a simple address book which works ok so it shouldn't be anything in my setup, Ross

hrossmvn commented 8 years ago

Have found the 'problem' with the address books - this error seems to occur if the N: field is not present for an entry. There are many such entries in the address books I want to process, surely there must be an easy error trap? I'm keeping looking but help will be appreciated (15 years since I last used Perl), Ross

hrossmvn commented 8 years ago

This change to _copy_name seems to fix it although I don't get the text "undefined" that I expected. Must learn more about OO Perl :-)

sub _copy_name { my ( $self, $textvcard, $vcard ) = @;

my ($node) = $text_vcard->get('n');

if (defined $text_vcard->get('n')) {

    $vcard->family_names(       [ $node->family   || () ] );
    $vcard->given_names(        [ $node->given    || () ] );
    $vcard->other_names(        [ $node->middle   || () ] );
    $vcard->honorific_prefixes( [ $node->prefixes || () ] );
    $vcard->honorific_suffixes( [ $node->suffixes || () ] );
} else {
    $vcard->family_names("undefined");
    $vcard->given_names("undefined");
    $vcard->other_names("undefined");
    $vcard->honorific_prefixes("undefined");
    $vcard->honorific_suffixes("undefined");
}

}

hrossmvn commented 8 years ago

Finally got there ("undefined") should be (["undefined"]) although I now prefer ([""]).

Hope this test for the N field in the vCard to be present can be included in the module? Ross

ranguard commented 8 years ago

thanks @hrossmvn will look at this when there's another review of this module - I'll leave the issue open until then

mmitch commented 8 years ago

I just stumbled over this problem, it seems to be still there. It can be triggered with this simple test:

#!/usr/bin/perl                                                                                                                                                                       
use strict;
use warnings;

use vCard;

my $filename = '/tmp/foo.vcf';

my $out = vCard->new;
$out->full_name( 'test' );
$out->as_file( $filename );

my $in = vCard->new;
$in->load_file( $filename );
printf "%f\n", $in->full_name;

The error comes from load_file(). vCard can't read the file it has created just before. I can provide this as a test case if you want to include it.