our
$VERSION
=
'0.15'
;
our
$AUTHORITY
=
'cpan:FAYLAND'
;
has
'+ua_class'
=> (
default
=>
'WWW::Mechanize::GZip'
);
sub
get_contacts {
my
(
$self
,
$email
,
$password
) =
@_
;
$self
->errstr(
undef
);
my
@contacts
;
my
$ua
=
$self
->ua;
$self
->debug(
"start get_contacts from Yahoo!"
);
$self
->submit_form(
form_name
=>
'login_form'
,
fields
=> {
login
=>
$email
,
passwd
=>
$password
,
},
) ||
return
;
my
$content
=
$ua
->content();
if
(
$content
=~ /=[\'\"]yregertxt/) {
$self
->errstr(
'Wrong Username or Password'
);
return
;
}
$self
->debug(
'Login OK'
);
$ua
->follow_link(
url_regex
=>
qr/import_export/
i );
$ua
->form_number(0);
$self
->submit_form(
button
=>
'submit[action_export_yahoo]'
,
);
$content
=
$ua
->content();
my
$i
;
while
(
$content
=~ /^\"(.*?)\"\,\".*?\"\,\"(.*?)\"\,\".*?\"\,\"(.*?)\"\,\".*?\"\,\".*?\"\,\"(.*?)\"/mg
) {
$i
++;
next
if
(
$i
== 1 );
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
,
};;
}
return
wantarray
?
@contacts
: \
@contacts
;
}
no
Moose;
__PACKAGE__->meta->make_immutable;
1;