| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$param->{'verbose'} || 0
$param->{'verbose'}
Truth table100%2/2
A
A= $param->{'verbose'}
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"username"} or $self->{"password"}
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"}
| |||||||||||||||||||||||||||||
| 45 | 9 | ▶ | if ( ( not $self->{username} ) or ( not $self->{password} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"username"} and $self->{"password"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | ▶ | if (not $self->{mech}->submit_form( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 5 | my $content = $self->{mech}->content(); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 5 | ▶ | if ( ref $self->{processor} eq 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | 1 | print STDERR "${$content}.\n"; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | return $content; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 5 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||