Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined value at line 208 #39

Open
hrossmvn opened this issue Sep 18, 2015 · 5 comments
Open

Undefined value at line 208 #39

hrossmvn opened this issue Sep 18, 2015 · 5 comments

Comments

@hrossmvn
Copy link

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
Copy link
Author

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
Copy link
Author

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, $text_vcard, $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
Copy link
Author

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
Copy link
Owner

ranguard commented Oct 4, 2015

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

@mmitch
Copy link

mmitch commented Jul 3, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants