| 1 | package Plone::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Config::INI::Reader; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::HomeDir; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use MooseX::NonMoose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | extends 'LWP::UserAgent'; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | has username => | |||||||||||||||||||||||||||||||||||||||||
| 19 | ( is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | predicate => '_has_username', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | writer => '_set_username', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | has password => | |||||||||||||||||||||||||||||||||||||||||
| 26 | ( is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | predicate => '_has_password', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | writer => '_set_password', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $uri = subtype as class_type('URI'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | coerce $uri | ||||||||||||||||||||||||||||||||||||||||||
| 34 | => from 'Str' | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | => via { URI->new( $_ ) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | has base_uri => | |||||||||||||||||||||||||||||||||||||||||
| 38 | ( is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | coerce => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | has config_file => | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ( is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | default => sub { File::HomeDir->my_home() . '/.plone-useragentrc' }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | has _config_data => | |||||||||||||||||||||||||||||||||||||||||
| 52 | ( is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 53 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | builder => '_build_config_data', | ||||||||||||||||||||||||||||||||||||||||||
| 56 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | sub BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=7 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | unless ( $self->_has_username && $self->_has_password ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->_has_username and $self->_has_password
MC/DC50%1/2
$self->_has_username and $self->_has_password
$self->_has_username
$self->_has_password
Truth table66%2/3
A and B
A= $self->_has_usernameB= $self->_has_password
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | my $config = $self->_config_data(); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | die 'Must provide a username and password or a valid config file' | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | unless $config && $config->{'_'}{username} && $config->{'_'}{password}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$config and $config->{"_"}{"username"} and $config->{"_"}{"password"}
$config and $config->{"_"}{"username"}
MC/DC0%0/3
$config and $config->{"_"}{"username"} and $config->{"_"}{"password"}
$config
$config->{"_"}{"username"}
$config->{"_"}{"password"}
Truth table25%1/4
A and B and C
A= $configB= $config->{"_"}{"username"}C= $config->{"_"}{"password"}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self->_set_username( $config->{'_'}{username} ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->_set_password( $config->{'_'}{password} ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | $self->cookie_jar( HTTP::Cookies->new() ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | unless $self->cookie_jar(); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | sub FOREIGNBUILDARGS | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | my $args = $class->BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my %copy = %{ $args }; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | delete @copy{ qw( base_uri username password config_file ) }; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | return %copy; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub _build_config_data | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_config_data: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $file = $self->config_file(); | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | return {} unless -f $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return Config::INI::Reader->read_file($file) || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
'Config::INI::Reader'->read_file($file) || {}
MC/DC0%0/1
'Config::INI::Reader'->read_file($file) || {}
'Config::INI::Reader'->read_file($file)
Truth table0%0/2
A
A= 'Config::INI::Reader'->read_file($file)
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | sub login | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | my $uri = $self->make_uri( '/login_form' ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my $response = | |||||||||||||||||||||||||||||||||||||||||
| 109 | $self->post( $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | { __ac_name => $self->username(), | ||||||||||||||||||||||||||||||||||||||||||
| 111 | __ac_password => $self->password(), | ||||||||||||||||||||||||||||||||||||||||||
| 112 | came_from => $self->base_uri(), | ||||||||||||||||||||||||||||||||||||||||||
| 113 | cookies_enabled => q{}, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 'form.submitted' => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | js_enabled => q{}, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | login_name => q{}, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | submit => 'Log in', | ||||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | die "Could not log in to $uri" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | unless $response->is_redirect(); | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | sub make_uri | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_uri: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | my $path = shift; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | my $uri = $self->base_uri()->clone(); | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | $uri->path( $uri->path() . $path ); | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | return $uri; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | __PACKAGE__->meta()->make_immutable(); | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | __END__ | ||||||||||||||||||||||||||||||||||||||||||