| 1 | 1 | ▶ | use 5.010; # mro | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | package Net::Travis::API::UA; | ||||||||||||||||||||||||||||||||
| 7 | 1 | $Net::Travis::API::UA::VERSION = '0.001001'; | |||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Travis Specific User Agent that handles authorization | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Moo qw( extends has ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use mro; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 1 | extends 'HTTP::Tiny'; | |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | sub _package_version { | ||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $vfield = join q[::], __PACKAGE__, q[VERSION]; | ||||||||||||||||||||||||||||||
|
Subroutine
_package_version: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 65 | ## no critic (BuiltinFunctions::ProhibitStringyEval,Lax::ProhibitStringyEval::ExceptForRequire) | ||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( eval "defined \$$vfield" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | ## no critic(ErrorHandling::RequireCheckingReturnValueOfEval) | ||||||||||||||||||||||||||||||||
| 68 | 0 | return eval "\$$vfield"; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | sub _ua_version { | ||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my ( $self, ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_ua_version: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 0 if not defined $self->_package_version; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 76 | 0 | return $self->_package_version; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _ua_name { return __PACKAGE__ } | ||||||||||||||||||||||||||||||
|
Subroutine
_ua_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | sub _ua_flags { | ||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ( $self, ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_ua_flags: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 82 | 0 | my $flags = ['cpan']; | |||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | push @{$flags}, 'dev' if not defined $self->_package_version; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | return $flags; | |||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | sub _agent { | ||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_agent: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 89 | 0 | my $own_ua = sprintf '%s/%s (%s)', $self->_ua_name, $self->_ua_version, ( join q{; }, @{ $self->_ua_flags } ); | |||||||||||||||||||||||||||||||
| 90 | 0 | my @agent_strings = ($own_ua); | |||||||||||||||||||||||||||||||
| 91 | 0 | for my $class ( @{ mro::get_linear_isa(__PACKAGE__) } ) { | |||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next unless $class->can('_agent'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | next if $class eq __PACKAGE__; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | 0 | push @agent_strings, $class->_agent(); | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | 0 | return join q[ ], @agent_strings; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | has 'http_prefix' => ( | ||||||||||||||||||||||||||||||||
| 110 | is => ro =>, | ||||||||||||||||||||||||||||||||
| 111 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | builder => sub { return 'https://api.travis-ci.org' }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 113 | 1 | ); | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 1 | has 'authtokens' => ( | |||||||||||||||||||||||||||||||
| 130 | is => rw =>, | ||||||||||||||||||||||||||||||||
| 131 | predicate => 'has_authtokens', | ||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | has 'json' => ( | ||||||||||||||||||||||||||||||||
| 143 | is => ro =>, | ||||||||||||||||||||||||||||||||
| 144 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 145 | builder => sub { | ||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | require JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
_build_json: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 147 | 0 | return JSON->new(); | |||||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||||||
| 149 | 1 | ); | |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | sub _add_auth_tokens { | ||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | my ( $self, $options ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_add_auth_tokens: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $options = {} if not defined $options; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ( exists $options->{travis_no_auth} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 155 | 0 | delete $options->{travis_no_auth}; | |||||||||||||||||||||||||||||||
| 156 | 0 | return $options; | |||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return $options unless $self->has_authtokens; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | return $options if exists $options->{headers} and exists $options->{headers}->{Authorization}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $options->{"headers"} and exists $options->{"headers"}{"Authorization"}
MC/DC0%0/2
exists $options->{"headers"} and exists $options->{"headers"}{"Authorization"}
exists $options->{"headers"}
exists $options->{"headers"}{"Authorization"}
Truth table0%0/3
A and B
A= exists $options->{"headers"}B= exists $options->{"headers"}{"Authorization"}
| |||||||||||||||||||||||||||||||||
| 160 | 0 | $options->{headers}->{Authorization} = [ map { 'token ' . $_ } @{ $self->authtokens } ]; | |||||||||||||||||||||||||||||||
| 161 | 0 | return $options; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | sub _expand_uri { | ||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my ( $self, $uri ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_expand_uri: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 166 | 0 | require URI; | |||||||||||||||||||||||||||||||
| 167 | 0 | return URI->new_abs( $uri, $self->http_prefix ); | |||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | sub FOREIGNBUILDARGS { | ||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my ( undef, @elems ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my $hash; | |||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( 1 == @elems and ref $elems[0] ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
1 == @elems and ref $elems[0]
MC/DC0%0/2
1 == @elems and ref $elems[0]
1 == @elems
ref $elems[0]
Truth table0%0/3
A and B
A= 1 == @elemsB= ref $elems[0]
| |||||||||||||||||||||||||||||||||
| 174 | 0 | $hash = $elems[0]; | |||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||
| 176 | elsif ( @elems % 2 == 0 ) { | ||||||||||||||||||||||||||||||||
| 177 | 0 | $hash = {@elems}; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||
| 180 | 0 | croak q[Uneven number of parameters or non-ref passed]; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | 0 | my %not = map { $_ => 1 } qw( http_prefix authtokens ); | |||||||||||||||||||||||||||||||
| 183 | 0 | my %out; | |||||||||||||||||||||||||||||||
| 184 | 0 | for my $key ( keys %{$hash} ) { | |||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | next if $not{$key}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | 0 | $out{$key} = $hash->{$key}; | |||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||
| 188 | 0 | return %out; | |||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | sub request { | ||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my ( $self, $method, $uri, $opts ) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 202 | 0 | my $result = $self->SUPER::request( $method, $self->_expand_uri($uri), $self->_add_auth_tokens($opts) ); | |||||||||||||||||||||||||||||||
| 203 | 0 | require Net::Travis::API::UA::Response; | |||||||||||||||||||||||||||||||
| 204 | return Net::Travis::API::UA::Response->new( | ||||||||||||||||||||||||||||||||
| 205 | json => $self->json, | ||||||||||||||||||||||||||||||||
| 206 | 0 | %{$result}, | |||||||||||||||||||||||||||||||
| 207 | ); | ||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | 1 | ▶ | no Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 1 | 1; | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | __END__ | ||||||||||||||||||||||||||||||||