blib/lib/WWW/Contact/Mail.pm

filter: Statementstmt 28.9% 11 / 38 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 22.4% 13 / 58 CC 9 SCAR 35.8
CC
9
Cov
21%
get_contacts
56.0
get_contacts_from_csv
12.0
BEGIN
1.0
CRAP 35.8
« blib/lib/WWW/Contact/Plaxo.pm ↑ Summary blib/lib/WWW/Contact/CN/163.pm »
1 package WWW::Contact::Mail;
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=7 SCAR=40.3
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 Mail.com");
18
19 # get to login form
20 0 ▶ $self->get('http://www.mail.com') || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://www.mail.com") or return 0 0 0
21  
22 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "mailcom", "fields", {"login", $email, "password", $password}) or return 0 0 0
23 form_name => 'mailcom',
24 fields => {
25 login => $email,
26 password => $password,
27 },
28 ) || return;
29
30 0 my $content = $ua->content();
31  
32 0 ▶ if ($content =~ /Invalid username\/password/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ m[Invalid username/password]gi) 0 0 0
33 0 $self->errstr('Wrong Username or Password');
34 0 return;
35 }
36 0 $self->debug('Login OK');
37  
38 0 ▶ $self->get("/scripts/addr/addressbook.cgi?showaddressbook=1") || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("/scripts/addr/addressbook.cgi?showaddressbook=1") or return 0 0 0
39 0 $ua->follow_link( text_regex => qr/Import\/Export/i );
40  
41 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "exportform") or return 0 0 0
42 form_name => 'exportform'
43 ) || return;
44  
45 0 my $address_content = $ua->content();
46 0 @contacts = get_contacts_from_csv($address_content);
47
48 0 ▶ return wantarray ? @contacts : \@contacts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
49 }
50  
51 sub get_contacts_from_csv {
52 0 ▶ my ($csv) = shift;
Subroutine get_contacts_from_csv: not called CC=3 SCAR=24.8
Pod undocumented
53 0 my @contacts;
54
55 # first_name, middle_name, last_name, nickname, e-mail.
56 0 my @lines = split(/\n/, $csv);
57 0 shift @lines; # skip the first line
58 0 foreach my $line (@lines) {
59 0 $line =~ s/"//g;
60 0 my @cols = split(',', $line);
61 0 push @contacts, {
62 name => $cols[0].' '.$cols[2],
63 email => $cols[4]
64 };
65 }
66
67 0 ▶ return wantarray ? @contacts : \@contacts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
68 }
69  
70 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 __PACKAGE__->meta->make_immutable;
72  
73 1 1;
74 __END__
75  
76 =head1 NAME
77  
78 WWW::Contact::Mail - Get contacts from Mail.com
79  
80 =head1 SYNOPSIS
81  
82 use WWW::Contact;
83 use Data::Dumper;
84
85 my $wc = WWW::Contact->new();
86 my @contacts = $wc->get_contacts('itsa@mail.com', 'password');
87 my $errstr = $wc->errstr;
88 if ($errstr) {
89 die $errstr;
90 } else {
91 print Dumper(\@contacts);
92 }
93  
94 =head1 DESCRIPTION
95  
96 Get contacts from Mail.com. Extends L<WWW::Contact::Base>
97  
98 Mail.com provides email addresses under different domain names. We currently support the most popular ones -
99 mail.com,
100 email.com,
101 iname.com,
102 cheerful.com,
103 consultant.com,
104 europe.com,
105 mindless.com,
106 earthling.net,
107 myself.com,
108 post.com,
109 techie.com,
110 usa.com,
111 writeme.com
112  
113 =head1 SEE ALSO
114  
115 L<WWW::Contact>, L<WWW::Contact::Base>, L<WWW::Mechanize>
116  
117 =head1 AUTHOR
118  
119 Sachin Sebastian, C<< <sachinjsk at cpan.org> >>
120  
121 =head1 COPYRIGHT & LICENSE
122  
123 Copyright 2008 Sachin Sebastian, all rights reserved.
124  
125 This program is free software; you can redistribute it and/or modify it
126 under the same terms as Perl itself.
127  
128 =cut
« blib/lib/WWW/Contact/Plaxo.pm ↑ Summary blib/lib/WWW/Contact/CN/163.pm »