Subject: | WWW::Contact::Yahoo enhancement |
Patch to allow returning all results from Yahoo contact information.
Subject: | Yahoo.pm.patch |
--- Yahoo.pm.bak 2008-12-09 16:34:01.000000000 -0500
+++ Yahoo.pm 2008-12-09 17:25:13.000000000 -0500
@@ -1,6 +1,7 @@
package WWW::Contact::Yahoo;
use Moose;
+use Text::CSV;
extends 'WWW::Contact::Base';
our $VERSION = '0.16';
@@ -44,19 +45,23 @@
);
$content = $ua->content();
- my $i;
- while ( $content
- =~ /^\"(.*?)\"\,\".*?\"\,\"(.*?)\"\,\".*?\"\,\"(.*?)\"\,\".*?\"\,\".*?\"\,\"(.*?)\"/mg
- ) {
- $i++;
- next if ( $i == 1 ); # skip the first line.
- next unless ( $3 or $4 );
- my $email = $3 || $4 . '@yahoo.com';
- my $name = ( $1 or $2 ) ? "$1 $2" : $4;
- push @contacts, {
- name => $name,
- email => $email,
- };;
+
+ my ($i, @header_columns, @rows);
+ my $header_row = (split(/\n/, $content))[0];
+ my $csv = Text::CSV->new();
+ $csv->parse($header_row."\n");
+ if (!defined($csv->fields())) { die $csv->error_diag(); }
+ @header_columns = $csv->fields();
+ my %columns = map { $header_columns[$_] => $_; } 0..$#header_columns;
+ @rows = map { $_ .= "\n"; } split(/\n/, $content);
+ shift(@rows);
+ foreach my $row (@rows) {
+ $csv->parse($row);
+ my @values = $csv->fields();
+
+ my %contact_info = map { $_ => $values[$columns{$_}] } keys(%columns);
+
+ push @contacts, \%contact_info;
}
return wantarray ? @contacts : \@contacts;