| 1 | package WWW::Contact::Lycos; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | extends 'WWW::Contact::Base'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.16'; | |||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:SACHINJSK'; | |||||||||
| 8 | |||||||||||
| 9 | sub get_contacts { | ||||||||||
| 10 | 0 | ▶ | my ($self, $email, $password) = @_; | ||||||||
|
Subroutine
get_contacts: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 11 | |||||||||||
| 12 | # reset errstr | ||||||||||
| 13 | 0 | $self->errstr(undef); | |||||||||
| 14 | 0 | my @contacts; | |||||||||
| 15 | |||||||||||
| 16 | 0 | my $ua = $self->ua; | |||||||||
| 17 | 0 | $self->debug("start get_contacts from lycos"); | |||||||||
| 18 | |||||||||||
| 19 | # Get username from email. | ||||||||||
| 20 | 0 | $email =~ /(.*)@.*/; | |||||||||
| 21 | 0 | my $username = $1; | |||||||||
| 22 | |||||||||||
| 23 | # get to login form | ||||||||||
| 24 | 0 | ▶ | $self->get('http://www.lycos.com/') || return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | $self->submit_form( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | form_number => 2, | ||||||||||
| 28 | fields => { | ||||||||||
| 29 | m_U => $username, | ||||||||||
| 30 | m_P => $password, | ||||||||||
| 31 | }, | ||||||||||
| 32 | ) || return; | ||||||||||
| 33 | |||||||||||
| 34 | 0 | my $content = $ua->content(); | |||||||||
| 35 | 0 | ▶ | if ($content =~ /password you provided don't match/ig) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | $self->errstr('Wrong Username or Password'); | |||||||||
| 37 | 0 | return; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | $self->debug('Login OK'); | |||||||||
| 41 | |||||||||||
| 42 | 0 | $self->get("http://mail.lycos.com/lycos/addrbook/ExportAddr.lycos?ptype=act&fileType=OUTLOOK"); | |||||||||
| 43 | |||||||||||
| 44 | 0 | my $address_content = $ua->content(); | |||||||||
| 45 | |||||||||||
| 46 | 0 | @contacts = get_contacts_from_csv($address_content); | |||||||||
| 47 | 0 | ▶ | return wantarray ? @contacts : \@contacts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | sub get_contacts_from_csv { | ||||||||||
| 51 | 0 | ▶ | my ($csv) = shift; | ||||||||
|
Subroutine
get_contacts_from_csv: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 52 | 0 | my @contacts; | |||||||||
| 53 | |||||||||||
| 54 | # first_name, middle_name, last_name, nickname, e-mail. | ||||||||||
| 55 | 0 | my @lines = split(/\n/, $csv); | |||||||||
| 56 | 0 | shift @lines; # skip the first line | |||||||||
| 57 | 0 | foreach my $line (@lines) { | |||||||||
| 58 | 0 | $line =~ s/"//g; | |||||||||
| 59 | 0 | my @cols = split(',', $line); | |||||||||
| 60 | 0 | push @contacts, { | |||||||||
| 61 | name => $cols[0].' '.$cols[2], | ||||||||||
| 62 | email => $cols[4] | ||||||||||
| 63 | }; | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | return wantarray ? @contacts : \@contacts; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 71 | |||||||||||
| 72 | 1 | 1; | |||||||||
| 73 | __END__ | ||||||||||
| 74 | |||||||||||
| 75 | =head1 NAME | ||||||||||
| 76 | |||||||||||
| 77 | WWW::Contact::Lycos - Get contacts from Lycos | ||||||||||
| 78 | |||||||||||
| 79 | =head1 SYNOPSIS | ||||||||||
| 80 | |||||||||||
| 81 | use WWW::Contact; | ||||||||||
| 82 | use Data::Dumper; | ||||||||||
| 83 | |||||||||||
| 84 | my $wc = WWW::Contact->new(); | ||||||||||
| 85 | my @contacts = $wc->get_contacts('itsa@lycos.com', 'password'); | ||||||||||
| 86 | my $errstr = $wc->errstr; | ||||||||||
| 87 | if ($errstr) { | ||||||||||
| 88 | die $errstr; | ||||||||||
| 89 | } else { | ||||||||||
| 90 | print Dumper(\@contacts); | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | =head1 DESCRIPTION | ||||||||||
| 94 | |||||||||||
| 95 | Get contacts from Lycos. Extends L<WWW::Contact::Base> | ||||||||||
| 96 | |||||||||||
| 97 | =head1 SEE ALSO | ||||||||||
| 98 | |||||||||||
| 99 | L<WWW::Contact>, L<WWW::Contact::Base>, L<WWW::Mechanize> | ||||||||||
| 100 | |||||||||||
| 101 | =head1 AUTHOR | ||||||||||
| 102 | |||||||||||
| 103 | Sachin Sebastian, C<< <sachinjsk at cpan.org> >> | ||||||||||
| 104 | |||||||||||
| 105 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 106 | |||||||||||
| 107 | Copyright 2008 Sachin Sebastian, all rights reserved. | ||||||||||
| 108 | |||||||||||
| 109 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 110 | under the same terms as Perl itself. | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||