blib/lib/WWW/Contact/Indiatimes.pm

filter: Statementstmt 28.9% 11 / 38 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 2 / 4 Podpod 0.0% 0 / 2 totaltotal 24.0% 13 / 54 CC 7 SCAR 29.3
CC
7
Cov
23%
get_contacts
30.0
get_contacts_from_csv
12.0
BEGIN
1.0
CRAP 18.8
« blib/lib/WWW/Contact/CN/163.pm ↑ Summary blib/lib/WWW/Contact/Lycos.pm »
1 package WWW::Contact::Indiatimes;
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 Indiatimes");
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://in.indiatimes.com/') || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://in.indiatimes.com/") or return 0 0 0
25  
26 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "loginfrm", "form_number", 3, "fields", {"login", $username, "passwd", $password}) or return 0 0 0
27 form_name => 'loginfrm',
28 form_number => 3,
29 fields => {
30 login => $username,
31 passwd => $password,
32 },
33 ) || return;
34
35 0 my $content = $ua->content();
36 0 ▶ if ($content =~ /Invalid User/ig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /Invalid User/gi) 0 0 0
37 0 $self->errstr('Wrong Username or Password');
38 0 return;
39 }
40  
41 0 $self->debug('Login OK');
42
43 0 $self->get("/home/$username/Contacts.csv");
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 # e-mail, file_as, first_name, last_name
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[2].' '.$cols[3],
63 email => $cols[0]
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::Indiatimes - Get contacts from Indiatimes
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@indiatimes.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 Indiatimes. Extends L<WWW::Contact::Base>
97  
98 =head1 SEE ALSO
99  
100 L<WWW::Contact>, L<WWW::Contact::Base>, L<WWW::Mechanize>
101  
102 =head1 AUTHOR
103  
104 Sachin Sebastian, C<< <sachinjsk at cpan.org> >>
105  
106 =head1 COPYRIGHT & LICENSE
107  
108 Copyright 2008 Sachin Sebastian, all rights reserved.
109  
110 This program is free software; you can redistribute it and/or modify it
111 under the same terms as Perl itself.
112  
113 =cut
« blib/lib/WWW/Contact/CN/163.pm ↑ Summary blib/lib/WWW/Contact/Lycos.pm »