blib/lib/WWW/Contact/Rediffmail.pm

filter: Statementstmt 24.4% 11 / 45 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 18.8% 13 / 69 CC 11 SCAR 38.5
CC
11
Cov
17%
get_contacts
72.0
get_contacts_from_thunderbird_csv
20.0
BEGIN
1.0
CRAP 47.0
« blib/lib/WWW/Contact/Gmail.pm ↑ Summary blib/lib/WWW/Contact/BG/Abv.pm »
1 package WWW::Contact::Rediffmail;
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.30';
7 1 our $AUTHORITY = 'cpan:SACHINJSK';
8  
9 sub get_contacts {
10 0 ▶ my ($self, $email, $password) = @_;
Subroutine get_contacts: not called CC=8 SCAR=42.8
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 Rediff");
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.rediff.com') || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://www.rediff.com") or return 0 0 0
25 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "loginform", "fields", {"login", $username, "passwd", $password}) or return 0 0 0
26 form_name => 'loginform',
27 fields => {
28 login => $username,
29 passwd => $password,
30 },
31 ) || return;
32  
33 0 my $content = $ua->content();
34 0 ▶ if ($content =~ /Your login failed/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /Your login failed/gi) 0 0 0
35 0 $self->errstr('Wrong Username or Password');
36 0 return;
37 }
38  
39 0 $self->debug('Login OK');
40 0 $ua->follow_link( url_regex => qr/login=/i );
41 0 $ua->follow_link( url_regex => qr/folder=inbox/i );
42 0 $content = $ua->content;
43  
44 # Go to new Rediffmail, if taken to old one.
45 0 ▶ if ($content =~ /new Rediffmail/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /new Rediffmail/i) 0 0 0
46 0 $ua->follow_link(text_regex => qr/new Rediffmail/i );
47 }
48 0 ▶ $self->get("/prism/exportaddrbook?output=web") || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("/prism/exportaddrbook?output=web") or return 0 0 0
49  
50 0 my $uri = $ua->uri->as_string;
51 0 $self->ua->current_form->action("$uri&service=thunderbird");
52 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "exportaddr", "fields", {"exporttype", "thunderbird"}) or return 0 0 0
53 form_name => 'exportaddr',
54 fields => {
55 exporttype => 'thunderbird',
56 },
57 ) || return;
58  
59 0 my $address_content = $ua->content();
60 0 @contacts = get_contacts_from_thunderbird_csv($address_content);
61 0 ▶ return wantarray ? @contacts : \@contacts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
62 }
63  
64 sub get_contacts_from_thunderbird_csv {
65 0 ▶ my ($csv) = shift;
Subroutine get_contacts_from_thunderbird_csv: not called CC=4 SCAR=30.0
Pod undocumented
66 0 my @contacts;
67
68 # dn:cn=tester cpan,mail=tester_cpan@rediffmail.com
69 0 my @lines = split(/\n/, $csv);
70 0 foreach my $line (@lines) {
71 0 ▶ next if $line !~ /^dn\:cn/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^dn\:cn/ 0 0 0
72 0 my ($name, $email) = ( $line =~ /cn=(.*?)\,mail=(.*?)$/ );
73 0 push @contacts, {
74 name => $name,
75 email => $email
76 };
77 }
78
79 0 ▶ return wantarray ? @contacts : \@contacts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
80 }
81  
82 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 1 __PACKAGE__->meta->make_immutable;
84  
85 1 1;
86 __END__
87  
88 =head1 NAME
89  
90 WWW::Contact::Rediffmail - Get contacts from Rediffmail
91  
92 =head1 SYNOPSIS
93  
94 use WWW::Contact;
95 use Data::Dumper;
96
97 my $wc = WWW::Contact->new();
98 my @contacts = $wc->get_contacts('itsa@rediffmail.com', 'password');
99 my $errstr = $wc->errstr;
100 if ($errstr) {
101 die $errstr;
102 } else {
103 print Dumper(\@contacts);
104 }
105  
106 =head1 DESCRIPTION
107  
108 Get contacts from Rediff Mail. Extends L<WWW::Contact::Base>
109  
110 =head1 SEE ALSO
111  
112 L<WWW::Contact>, L<WWW::Contact::Base>, L<WWW::Mechanize>
113  
114 =head1 AUTHOR
115  
116 Sachin Sebastian, C<< <sachinjsk at cpan.org> >>
117  
118 =head1 COPYRIGHT & LICENSE
119  
120 Copyright 2008 Sachin Sebastian, all rights reserved.
121  
122 This program is free software; you can redistribute it and/or modify it
123 under the same terms as Perl itself.
124  
125 =cut
« blib/lib/WWW/Contact/Gmail.pm ↑ Summary blib/lib/WWW/Contact/BG/Abv.pm »