blib/lib/WWW/Anonymouse.pm

filter: Statementstmt 55.7% 34 / 61 Branchbran 18.7% 3 / 16 Conditioncond 42.8% 3 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 52.6% 10 / 19 Podpod 100% 3 / 3 totaltotal 49.0% 54 / 110 CC 13 SCAR 30.1
CC
13
Cov
48%
send
72.0
_ua_content_cb
6.0
new
4.2
CRAP 20.3
↑ Summary
1 package WWW::Anonymouse;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.04';
11  
12 2 ▶use constant DEBUG => $ENV{ WWW_ANONYMOUSE_DEBUG } || 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'WWW_ANONYMOUSE_DEBUG'} || 0
l!l
02
MC/DC0%0/1
$ENV{'WWW_ANONYMOUSE_DEBUG'} || 0
$ENV{'WWW_ANONYMOUSE_DEBUG'}
Truth table50%1/2
A
A= $ENV{'WWW_ANONYMOUSE_DEBUG'}
Aresult
11
00
13 2 ▶use constant MAX_BYTES => 3072;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶sub new {
Subroutine new: called CC=4 SCAR=14.3
Pod documented
16 4 my ($class, %params) = @_;
17 4 ▶ if ( $class eq __PACKAGE__ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 0 4 4
18 0 Carp::croak __PACKAGE__,
19 ' is a virtual class; use the Email or News class';
20 }
21  
22 4 ▶ unless ( ref $params{ua} and $params{ua}->isa( q(LWP::UserAgent) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $params{"ua"} and $params{"ua"}->isa("LWP::UserAgent")) 2 2 4
Condition66%2/3
ref $params{"ua"} and $params{"ua"}->isa("LWP::UserAgent")
!ll&&!rl&&r
202
MC/DC50%1/2
ref $params{"ua"} and $params{"ua"}->isa("LWP::UserAgent")
ref $params{"ua"} $params{"ua"}->isa("LWP::UserAgent")
Truth table66%2/3
A and B
A= ref $params{"ua"}B= $params{"ua"}->isa("LWP::UserAgent")
ABresult
0X0
100
111
23 2 $params{ua} = LWP::UserAgent->new( agent => __PACKAGE__.'/'.$VERSION );
24 }
25  
26 4 return bless \%params, $class;
27 }
28  
29 0 ▶sub error {
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
30 0 return $_[0]->{error};
31 }
32  
33 0 ▶sub _ua_content_cb {
Subroutine _ua_content_cb: not called CC=2 SCAR=17.9
34 0 my ($data, $res, $proto) = @_;
35 0 $res->add_content(\$data);
36  
37 # Abort the request if enough content is received to parse for status.
38 0 ▶ die if length $res->content > MAX_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
if length $res->content > 3072 0 0 0
39 }
40  
41 0 ▶sub send {
Subroutine send: not called CC=8 SCAR=42.8
Pod documented
42 0 my ($self, %params) = @_;
43 0 my %fields;
44  
45 0 ▶ unless ( $fields{qw( to )} = $params{qw( to )} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fields{"to"} = $params{"to"}) 0 0 0
46 0 $self->{error} = qq(Missing field "to");
47 0 return;
48 }
49  
50 0 for my $field ( qw( subject text ) ) {
51 0 ▶ $fields{$field} = $params{$field} || '';
Condition0%0/2
$params{$field} || ''
l!l
00
MC/DC0%0/1
$params{$field} || ''
$params{$field}
Truth table0%0/2
A
A= $params{$field}
Aresult
11
00
52 }
53  
54 my $res = $self->{ua}->post(
55 0 $self->_url, \%fields, ':read_size_hint' => MAX_BYTES,
56 ':content_cb' => \&_ua_content_cb,
57 );
58 0 ▶ unless ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 0 0
59 0 $self->{error} = $res->status_line;
60 0 return;
61 }
62  
63 # TODO: consider using HTML::TreeBuilder::XPath
64  
65 0 $self->{error} = 'Unknown error';
66 0 my $cref = $res->content_ref;
67  
68 0 ▶ if ( $$cref !~ /<FONT size="\+2"/g ) { }
Branch: 3 branches
BranchTrueFalseTotal
if (not $$cref =~ /<FONT size="\+2"/g) { } 0 0 0
elsif ($$cref =~ /\G color="#FF0000">(?:Mixmaster-)?Error - ([^>]+?)\!?</cg) { } 0 0 0
elsif ($$cref =~ /\G>(?:Email|Posting) has been sent anonymously/) { } 0 0 0
69 elsif ( $$cref =~ /\G color="#FF0000">(?:Mixmaster-)?Error - ([^>]+?)\!?</gc ) {
70 0 $self->{error} = $1;
71 }
72 elsif ( $$cref =~ /\G>(?:Email|Posting) has been sent anonymously/ ) {
73 0 $self->{error} = undef;
74 0 return 1;
75 }
76  
77 0 return;
78 }
79  
80 BEGIN {
81 package WWW::Anonymouse::Email;
82 2 ▶ use base qw( WWW::Anonymouse );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
83 0 ▶ sub _url { 'http://anonymouse.org/cgi-bin/anon-email.cgi' }
Subroutine _url: not called CC=1 SCAR=6.9
84 0 ▶ sub _referer { 'http://anonymouse.org/anonemail.html' }
Subroutine _referer: not called CC=1 SCAR=6.9
85 }
86  
87 BEGIN {
88 package WWW::Anonymouse::News;
89 2 ▶ use base qw( WWW::Anonymouse );
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: not called CC=1 SCAR=0.0
90 0 ▶ sub _url { 'http://anonymouse.org/cgi-bin/anon-news.cgi' }
Subroutine _url: not called CC=1 SCAR=6.9
91 0 ▶ sub _referer { 'http://anonymouse.org/anonnews.html' }
Subroutine _referer: not called CC=1 SCAR=6.9
92 }
93  
94 2 1;
95  
96 __END__
↑ Summary