Skip Menu |

This queue is for tickets about the WWW-Google-Contacts CPAN distribution.

Report information
The Basics
Id: 62718
Status: resolved
Priority: 0/
Queue: WWW-Google-Contacts

People
Owner: Nobody in particular
Requestors: mike [...] mikebaas.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.16
Fixed in: (no value)



Subject: UserDefined - Doesn't handle multiple user defined fields
A contact with more than one user defined field will fail with the following error: Attribute (key) is required at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Types.pm line 294 WWW::Google::Contacts::Types::__ANON__('HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeCoercion.pm line 63 Moose::Meta::TypeCoercion::__ANON__('HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeCoercion.pm line 97 Moose::Meta::TypeCoercion::coerce('Moose::Meta::TypeCoercion=HASH(0x9a9b6e0)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeConstraint.pm line 90 Moose::Meta::TypeConstraint::coerce('Moose::Meta::TypeConstraint::Class=HASH(0x9a9afd0)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types.pm line 480 MooseX::Types::__ANON__('HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Types.pm line 300 WWW::Google::Contacts::Types::__ANON__('HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeCoercion.pm line 63 Moose::Meta::TypeCoercion::__ANON__('HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeCoercion.pm line 97 Moose::Meta::TypeCoercion::coerce('Moose::Meta::TypeCoercion=HASH(0x9a9b9d0)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread-multi/Moose/Meta/TypeConstraint.pm line 90 Moose::Meta::TypeConstraint::coerce('Moose::Meta::TypeConstraint::Parameterizable=HASH(0x9a9bc90)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm line 199 eval {...} called at /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm line 198 MooseX::Types::TypeDecorator::AUTOLOAD('MooseX::Types::TypeDecorator=HASH(0x962cf20)', 'HASH(0xaab0058)') called at accessor user_defined defined at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Contact.pm line 365 WWW::Google::Contacts::Contact::user_defined('WWW::Google::Contacts::Contact=HASH(0xa12c020)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Base.pm line 78 WWW::Google::Contacts::Base::set_from_server('WWW::Google::Contacts::Contact=HASH(0xa12c020)', 'HASH(0xac396c0)') called at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Roles/List.pm line 79 WWW::Google::Contacts::Roles::List::next('WWW::Google::Contacts::ContactList=HASH(0x960ed60)') called at google_contact.pl line 13 at /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm line 201 MooseX::Types::TypeDecorator::AUTOLOAD('MooseX::Types::TypeDecorator=HASH(0x962cf20)', 'HASH(0xaab0058)') called at accessor user_defined defined at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Contact.pm line 365 WWW::Google::Contacts::Contact::user_defined('WWW::Google::Contacts::Contact=HASH(0xa12c020)', 'HASH(0xaab0058)') called at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Base.pm line 78 WWW::Google::Contacts::Base::set_from_server('WWW::Google::Contacts::Contact=HASH(0xa12c020)', 'HASH(0xac396c0)') called at /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Roles/List.pm line 79 WWW::Google::Contacts::Roles::List::next('WWW::Google::Contacts::ContactList=HASH(0x960ed60)') called at google_contact.pl line 13 The data for multiple user defined fields looks like this: $VAR1 = { '8:00 AM' => { 'value' => 'Birth Time' }, 'Cayman Brac, Cayman Islands' => { 'value' => 'Birth Place' } }; They keys and the values look switched to me. Don't know if the coersion is doing the right thing for multiple UserDefined fields. I think it should be an array of hashes. class_type UserDefined, { class => 'WWW::Google::Contacts::Type::UserDefined' }; coerce UserDefined, from HashRef, via { WWW::Google::Contacts::Type::UserDefined->new( $_ ) }; I'm hoping to leverage this code for an iPhone app I'm writing, so it'd be great to fix it! I spent about 3 hours on it and I couldn't figure it out. I'm hoping it is an easy fix. Thanks, mb
One solution would be to treat all user_defined fields as hashrefs. Since you can't know what someone will be naming they fields, you can't make them accessors. It looks like the Google Contacts API returns two different structures whether or not there is one or more values. With one value, you get structure like: { key => 'Label', value => 'Custom value', } With two values, you get this instead: { Label => { value => 'Custom value' }, Label2 => { value => 'Custom value 2' }, } In Types.pm, you can create a subtype that handles these cases. subtype HashRefOfUserDefined, as HashRef, where { ! defined $_->{key} && ! defined $_->{value} }; coerce HashRefOfUserDefined, from HashRef, via { return { $_->{key} => $_->{value} }; }; The user_defined accessor then return a hashref: has user_defined => ( #isa => ArrayRefOfUserDefined, isa => HashRefOfUserDefined, is => 'rw', predicate => 'has_user_defined', traits => ['XmlField'], xml_key => 'gContact:userDefinedField', coerce => 1, ); You can then go: $contact->user_defined->{Label} I think that's the best solution for these custom fields. Let me know if you decide to implement the change. Thanks, mb On Fri Nov 05 05:18:40 2010, MBAAS wrote: Show quoted text
> A contact with more than one user defined field will fail with the > following error: > > Attribute (key) is required at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Types.pm > line 294 > WWW::Google::Contacts::Types::__ANON__('HASH(0xaab0058)') > called > at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeCoercion.pm > line 63 > Moose::Meta::TypeCoercion::__ANON__('HASH(0xaab0058)') called > at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeCoercion.pm > line 97 > >
Moose::Meta::TypeCoercion::coerce('Moose::Meta::TypeCoercion=HASH(0x9a9b6e0)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeConstraint.pm > line 90 > >
Moose::Meta::TypeConstraint::coerce('Moose::Meta::TypeConstraint::Class=HASH(0x9a9afd0)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types.pm line 480 > MooseX::Types::__ANON__('HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Types.pm > line 300 > WWW::Google::Contacts::Types::__ANON__('HASH(0xaab0058)') > called > at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeCoercion.pm > line 63 > Moose::Meta::TypeCoercion::__ANON__('HASH(0xaab0058)') called > at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeCoercion.pm > line 97 > >
Moose::Meta::TypeCoercion::coerce('Moose::Meta::TypeCoercion=HASH(0x9a9b9d0)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/i686-linux-thread- > multi/Moose/Meta/TypeConstraint.pm > line 90 > >
Moose::Meta::TypeConstraint::coerce('Moose::Meta::TypeConstraint::Parameterizable=HASH(0x9a9bc90)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm > line 199 > eval {...} called at > /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm > line 198 > >
MooseX::Types::TypeDecorator::AUTOLOAD('MooseX::Types::TypeDecorator=HASH(0x962cf20)', Show quoted text
> 'HASH(0xaab0058)') called at accessor user_defined defined at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Contact.pm > line 365 > >
WWW::Google::Contacts::Contact::user_defined('WWW::Google::Contacts::Contact=HASH(0xa12c020)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Base.pm line > 78 > >
WWW::Google::Contacts::Base::set_from_server('WWW::Google::Contacts::Contact=HASH(0xa12c020)', Show quoted text
> 'HASH(0xac396c0)') called at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Roles/List.pm > line 79 > >
WWW::Google::Contacts::Roles::List::next('WWW::Google::Contacts::ContactList=HASH(0x960ed60)') Show quoted text
> called at google_contact.pl line 13 > at > /usr/local/lib/perl5/site_perl/5.10.1/MooseX/Types/TypeDecorator.pm > line 201 > >
MooseX::Types::TypeDecorator::AUTOLOAD('MooseX::Types::TypeDecorator=HASH(0x962cf20)', Show quoted text
> 'HASH(0xaab0058)') called at accessor user_defined defined at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Contact.pm > line 365 > >
WWW::Google::Contacts::Contact::user_defined('WWW::Google::Contacts::Contact=HASH(0xa12c020)', Show quoted text
> 'HASH(0xaab0058)') called at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Base.pm line > 78 > >
WWW::Google::Contacts::Base::set_from_server('WWW::Google::Contacts::Contact=HASH(0xa12c020)', Show quoted text
> 'HASH(0xac396c0)') called at > /usr/local/lib/perl5/site_perl/5.10.1/WWW/Google/Contacts/Roles/List.pm > line 79 > >
WWW::Google::Contacts::Roles::List::next('WWW::Google::Contacts::ContactList=HASH(0x960ed60)') Show quoted text
> called at google_contact.pl line 13 > > > The data for multiple user defined fields looks like this: > > $VAR1 = { > '8:00 AM' => { > 'value' => 'Birth Time' > }, > 'Cayman Brac, Cayman Islands' => { > 'value' => 'Birth Place' > } > }; > > They keys and the values look switched to me. > > Don't know if the coersion is doing the right thing for multiple > UserDefined fields. I think it should be an array of hashes. > > class_type UserDefined, > { class => 'WWW::Google::Contacts::Type::UserDefined' }; > > coerce UserDefined, > from HashRef, > via { WWW::Google::Contacts::Type::UserDefined->new( $_ ) }; > > > I'm hoping to leverage this code for an iPhone app I'm writing, so > it'd > be great to fix it! I spent about 3 hours on it and I couldn't figure > it out. I'm hoping it is an easy fix. > > Thanks, > > mb > > > >
Hi Mike Thanks a lot for the bug report! Show quoted text
> With two values, you get this instead: > > { >  Label => { >    value => 'Custom value' >  }, >  Label2 => { >    value => 'Custom value 2' >  }, > }
Yes this looks wrong. Ideally I'd like the user defined fields to be an array ref with hashrefs, so it works like the other fields, like phone number and so on. It's a bit of a busy time right now (isn't that always the sad truth), but I'll try to get a fix out in the next few days. cheers Magnus
This has now been resolved in version 0.17, closing ticket. cheers Magnus