blib/lib/WWW/DanDomain.pm

filter: Statementstmt 92.7% 51 / 55 Branchbran 95.0% 19 / 20 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 84.6% 11 / 13 Podpod 100% 4 / 4 totaltotal 93.3% 98 / 105 CC 14 SCAR 16.3
CC
14
Cov
94%
retrieve
10.0
new
4.0
__ANON__
2.0
CRAP 5.1
↑ Summary
1 package WWW::DanDomain;
2  
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use WWW::Mechanize::Cached;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $VERSION = '0.08';
12  
13 14 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
14 14 my ( $class, $param ) = @_;
15  
16 14 my $mech;
17  
18 14 my $agent = __PACKAGE__ . "-$VERSION";
19  
20 14 ▶ if ( $param->{mech} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($param->{'mech'}) { } 11 3 14
elsif ($param->{'cache'}) { } 0 3 3
21 11 $mech = $param->{mech};
22 } elsif ( $param->{cache} ) {
23 0 $mech = WWW::Mechanize::Cached->new( agent => $agent );
24 } else {
25 3 $mech = WWW::Mechanize->new( agent => $agent );
26 }
27  
28 my $self = bless {
29 base_url => 'http://www.billigespil.dk/admin',
30 username => $param->{username},
31 password => $param->{password},
32 url => $param->{url},
33 verbose => $param->{verbose} || 0,
34 mech => $mech,
35 processor => $param->{processor},
36 14 ▶ }, $class;
Condition100%2/2
$param->{'verbose'} || 0
l!l
212
MC/DC100%1/1
$param->{'verbose'} || 0
$param->{'verbose'}
Truth table100%2/2
A
A= $param->{'verbose'}
Aresult
11
00
37  
38 14 return $self;
39 }
40  
41 10 ▶sub retrieve {
Subroutine retrieve: called CC=10 SCAR=23.0
Pod documented
42 10 my ( $self, $stat ) = @_;
43  
44 10 ▶ if ( $self->{username} || $self->{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"username"} or $self->{"password"}) 9 1 10
Condition100%3/3
$self->{"username"} or $self->{"password"}
l!l&&r!l&&!r
811
MC/DC100%2/2
$self->{"username"} or $self->{"password"}
$self->{"username"} $self->{"password"}
Truth table100%3/3
A or B
A= $self->{"username"}B= $self->{"password"}
ABresult
1X1
011
000
45 9 ▶ if ( ( not $self->{username} ) or ( not $self->{password} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"username"} and $self->{"password"}) 2 7 9
Condition100%3/3
$self->{"username"} and $self->{"password"}
!ll&&!rl&&r
117
MC/DC100%2/2
$self->{"username"} and $self->{"password"}
$self->{"username"} $self->{"password"}
Truth table100%3/3
A and B
A= $self->{"username"}B= $self->{"password"}
ABresult
0X0
100
111
46 2 croak 'Both username and password is required for authentication';
47 }
48  
49 $self->{mech}->get( $self->{base_url} )
50 7 ▶ or croak "Unable to retrieve base URL: $@";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"mech"}->get($self->{"base_url"}) or croak("Unable to retrieve base URL: $@") 6 1 7
51  
52 6 ▶ if (not $self->{mech}->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"mech"}->submit_form("form_number", 0, "fields", {"UserName", $self->{"username"}, "Password", $self->{"password"}})) 1 5 6
53 form_number => 0,
54 fields => {
55 UserName => $self->{username},
56 Password => $self->{password},
57 }
58 )
59 )
60 {
61 1 croak 'Unable to authenticate';
62 }
63 }
64  
65 6 ▶ $self->{mech}->get( $self->{url} ) or croak "Unable to retrieve URL: $@";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"mech"}->get($self->{"url"}) or croak("Unable to retrieve URL: $@") 5 1 6
66  
67 5 my $content = $self->{mech}->content();
68  
69 5 ▶ if ( ref $self->{processor} eq 'CODE' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'processor'} eq 'CODE') { } 1 4 5
elsif (ref $self->{'processor'}) { } 1 3 4
70 1 return &{ $self->{processor} }( \$content, $stat );
71 } elsif ( ref $self->{processor} ) {
72 1 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 1 $self->{processor}->can('process');
74 }
75 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
76 0 croak q{Your processor does not implement 'process' method};
77 1 };
78 1 return $self->{processor}->process( \$content, $stat );
79 } else {
80 3 return $self->process( \$content, $stat );
81 }
82 }
83  
84 0 ▶sub processor {
Subroutine processor: not called CC=1 SCAR=6.9
Pod documented
85 0 my ( $self, $content ) = @_;
86  
87 0 return $self->process($content);
88 }
89  
90 3 ▶sub process {
Subroutine process: called CC=2 SCAR=6.9
Pod documented
91 3 my ( $self, $content ) = @_;
92  
93 3 ▶ if ( $self->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 1 2 3
94 1 print STDERR "${$content}.\n";
95 }
96  
97 3 return $content;
98 }
99  
100 5 1;
101  
102 __END__
↑ Summary