blib/lib/WWW/Mechanize/SpamCop.pm

filter: Statementstmt 22.7% 15 / 66 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 16.9% 23 / 136 CC 24 SCAR 43.6
CC
24
Cov
13%
new
156.0
report_one
42.0
report_all
42.0
CRAP 77.9
↑ Summary
1 package WWW::Mechanize::SpamCop;
2  
3 # $Abso: abso/divers/mat/perl/WWW-Mechanize-SpamCop/SpamCop.pm,v 1.4 2003/08/05 14:28:00 mat Exp $
4  
5 #---[ pod head ]---{{{
6  
7 =head1 NAME
8  
9 WWW::Mechanize::SpamCop - SpamCop reporting automation.
10  
11 =head1 SYNOPSIS
12  
13 use WWW::Mechanize::SpamCop;
14  
15 $s = WWW::Mechanize::SpamCop->new(
16 login => 'login@spamcop.net',
17 passwd => 'passwd'
18 );
19  
20 $s->report_one;
21  
22 $s->report_all;
23  
24  
25 =head1 ABSTRACT
26  
27 WWW::Mechanize::SpamCop is used to automate spam reporting on spamcop.net's web
28 site.
29  
30 =cut
31  
32 =head1 DESCRIPTION
33  
34 =cut
35  
36 #---}}}
37  
38 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 @ISA = qw(WWW::Mechanize);
45  
46 1 $VERSION = '0.08';
47  
48 #---[ sub new ]---{{{
49  
50 =head2 new
51  
52 Create a new WWW::Mechanize::SpamCop object
53  
54 The required arguments are login and passwd, you can also pass it a host,
55 defaulting to 'www.spamcop.net:80' (the :80 is needed because of the
56 authentication), a realm, defaulting to 'your SpamCop account' which is the
57 domain's realm for autentication. and a report default to 'Report Now', which
58 is the name of the link on the web page.
59  
60 =cut
61  
62 0 ▶sub new {
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
63 0 my $proto = shift;
64 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
65 0 my %p = @_;
66  
67 croak 'You must specify a login'
68 0 ▶ unless ( exists( $p{login} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"login"} 0 0 0
69 croak 'You must specify a passwd'
70 0 ▶ unless ( exists( $p{passwd} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"passwd"} 0 0 0
71  
72 0 my $login = delete( $p{login} );
73 0 my $passwd = delete( $p{passwd} );
74  
75 0 my $self = $class->SUPER::new(%p);
76  
77 0 ▶ $self->{host} = $p{host} || 'www.spamcop.net:80';
Condition0%0/2
$p{'host'} || 'www.spamcop.net:80'
l!l
00
MC/DC0%0/1
$p{'host'} || 'www.spamcop.net:80'
$p{'host'}
Truth table0%0/2
A
A= $p{'host'}
Aresult
11
00
78 0 ▶ $self->{realm} = $p{realm} || 'your SpamCop account';
Condition0%0/2
$p{'realm'} || 'your SpamCop account'
l!l
00
MC/DC0%0/1
$p{'realm'} || 'your SpamCop account'
$p{'realm'}
Truth table0%0/2
A
A= $p{'realm'}
Aresult
11
00
79 0 ▶ $self->{report} = $p{report} || 'Report Now';
Condition0%0/2
$p{'report'} || 'Report Now'
l!l
00
MC/DC0%0/1
$p{'report'} || 'Report Now'
$p{'report'}
Truth table0%0/2
A
A= $p{'report'}
Aresult
11
00
80 0 ▶ $self->{regex_remove_unreported} = $p{regex_remove_unreported} || qr/^Remove all unreported/;
Condition0%0/2
$p{'regex_remove_unreported'} || qr/^Remove all unreported/
l!l
00
MC/DC0%0/1
$p{'regex_remove_unreported'} || qr/^Remove all unreported/
$p{'regex_remove_unreported'}
Truth table0%0/2
A
A= $p{'regex_remove_unreported'}
Aresult
11
00
81 0 ▶ $self->{regex_removed_count} = $p{regex_removed_count} || qr/Removed\s+([0-9]+)\s+unreported/i;
Condition0%0/2
$p{'regex_removed_count'} || qr/Removed\s+([0-9]+)\s+unreported/i
l!l
00
MC/DC0%0/1
$p{'regex_removed_count'} || qr/Removed\s+([0-9]+)\s+unreported/i
$p{'regex_removed_count'}
Truth table0%0/2
A
A= $p{'regex_removed_count'}
Aresult
11
00
82 0 ▶ $self->{sendformname} = $p{sendformname} || 'sendreport';
Condition0%0/2
$p{'sendformname'} || 'sendreport'
l!l
00
MC/DC0%0/1
$p{'sendformname'} || 'sendreport'
$p{'sendformname'}
Truth table0%0/2
A
A= $p{'sendformname'}
Aresult
11
00
83 0 $self->{login} = $login;
84 0 $self->{passwd} = $passwd;
85  
86 0 ▶ croak 'SomeThing went wrong'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get(qq[http://$self->{"host"}/]) 0 0 0
87 unless $self->get("http://$self->{host}/");
88  
89 0 $self->form_number(1);
90 0 $self->field('username', $self->{login});
91 0 $self->field('password', $self->{passwd});
92 0 ▶ $self->click() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->click or return undef 0 0 0
93  
94 0 return $self;
95 }
96  
97 #---}}}
98  
99 #---[ sub report_one ]---{{{
100  
101 =head2 report_one
102  
103 Report one spam
104  
105 returns :
106  
107 =over
108  
109 =item undef
110  
111 no spam was found
112  
113 =item 1
114  
115 if a spam was reported
116  
117 =item 2
118  
119 if the spam was too old
120  
121 =back
122  
123 =cut
124  
125 0 ▶sub report_one {
Subroutine report_one: not called CC=6 SCAR=37.4
Pod documented
126 0 my $self = shift;
127  
128 0 ▶ if ( $self->follow_link( text => $self->{report} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->follow_link('text', $self->{'report'})) { } 0 0 0
129 # Probably makes no sense because currently there's a submission form instead of link:
130 #if ( $self->find_link( text => $self->{report} ) ) {
131 # return 2;
132 #}
133  
134 0 my @forms = $self->forms();
135 # Look for "send report" form:
136 0 ▶ if (scalar(@forms) < 1) { return undef };
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @forms < 1) 0 0 0
137 0 ▶ @forms = grep { defined ($_->attr("name")) && $_->attr("name") eq $self->{sendformname}} @forms;
Condition0%0/3
defined $_->attr('name') && $_->attr('name') eq $self->{'sendformname'}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->attr('name') && $_->attr('name') eq $self->{'sendformname'}
defined $_->attr('name') $_->attr('name') eq $self->{'sendformname'}
Truth table0%0/3
A && B
A= defined $_->attr('name')B= $_->attr('name') eq $self->{'sendformname'}
ABresult
0X0
100
111
138 # If a form with the proper name is found, submit report:
139 0 ▶ if (@forms) {
Branch: 1 branch
BranchTrueFalseTotal
if (@forms) { } 0 0 0
140 0 $self->form_name($self->{sendformname});
141 0 ▶ $self->click() or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->click or return undef 0 0 0
142 0 return 1;
143 } else {
144 0 return 2;
145 }
146  
147 } else {
148 0 return undef;
149 }
150 }
151  
152 #---}}}
153  
154 #---[ sub report_all ]---{{{
155  
156 =head2 report_all
157  
158 Report all waiting spams
159  
160 If called in a scalar context, returns the number of spam reported. If in an
161 array context, returns an array containing the number of reported spams and the
162 number of old spams (not reported).
163  
164 =cut
165  
166 0 ▶sub report_all {
Subroutine report_all: not called CC=6 SCAR=37.4
Pod documented
167 0 my $self = shift;
168 0 my ( $i, $j ) = ( 0, 0 );
169 0 ▶ while ( my $r = $self->report_one ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = $self->report_one) 0 0 0
170 0 ▶ $i++ if ( $r == 1 );
Branch: 1 branch
BranchTrueFalseTotal
if $r == 1 0 0 0
171 0 ▶ $j++ if ( $r == 2 );
Branch: 1 branch
BranchTrueFalseTotal
if $r == 2 0 0 0
172 }
173  
174 0 ▶ return unless defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
175 0 ▶ return ( wantarray ? ( $i, $j ) : $i );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
176 }
177  
178 #---}}}
179  
180 #---[ sub remove_unreported ]---{{{
181  
182 =head2 remove_unreported
183  
184  
185 Removes all unreported spams. Returns the number of removed spams as scalar value.
186  
187 =cut
188  
189 0 ▶sub remove_unreported {
Subroutine remove_unreported: not called CC=3 SCAR=24.8
Pod documented
190 0 my $self = shift;
191 0 my $count = 0;
192 0 ▶ if ( $self->follow_link( text_regex => $self->{regex_remove_unreported} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->follow_link('text_regex', $self->{'regex_remove_unreported'})) { } 0 0 0
193 0 my $content = $self->content( format => "text" );
194 0 my $regex_removed_count = $self->{regex_removed_count};
195 0 ▶ if ($content =~ qr/$regex_removed_count/si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ qr/$regex_removed_count/is) 0 0 0
196 0 $count = $1;
197 }
198 0 return $count;
199 } else {
200 0 return 0;
201 }
202 }
203  
204 #---}}}
205  
206 1 1;
207 __END__
↑ Summary