| 1 | package UserAgent::Any; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use 5.036; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | our $VERSION = 0.05; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | our @CARP_NOT = 'UserAgent::Any::Wrapper'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # We expect a single argument to this class, so we take it without the need to | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # pass it in a hash. See: | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # https://metacpan.org/pod/Moo#BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=18.9
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | my ($orig, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | return {ua => $args[0]} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@args == 1 and ref $args[0] ne "HASH" || !builtin::blessed($args[0])
ref $args[0] ne "HASH" or not builtin::blessed($args[0])
MC/DC0%0/3
@args == 1 and ref $args[0] ne "HASH" || !builtin::blessed($args[0])
@args == 1
ref $args[0] ne "HASH"
not builtin::blessed($args[0])
Truth table25%1/4
A and B or not(C)
A= @args == 1B= ref $args[0] ne "HASH"C= not builtin::blessed($args[0])
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | if @args == 1 && (ref($args[0]) ne 'HASH' || !blessed($args[0])); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return $class->$orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | has _impl => ( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | init_arg => 'ua', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | handles => 'UserAgent::Any::Impl', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | coerce => sub ($ua) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | croak 'Passed User Agent object must be a blessed reference' unless blessed($ua); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | if ($ua isa LWP::UserAgent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | require UserAgent::Any::Impl::LwpUserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | return UserAgent::Any::Impl::LwpUserAgent->new(ua => $ua); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } elsif ($ua isa AnyEvent::UserAgent) { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | require UserAgent::Any::Impl::AnyEventUserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return UserAgent::Any::Impl::AnyEventUserAgent->new(ua => $ua); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } elsif ($ua isa Mojo::UserAgent) { | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | require UserAgent::Any::Impl::MojoUserAgent; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return UserAgent::Any::Impl::MojoUserAgent->new(ua => $ua); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } elsif ($ua isa HTTP::Promise) { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | require UserAgent::Any::Impl::HttpPromise; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return UserAgent::Any::Impl::HttpPromise->new(ua => $ua); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } elsif ($ua->DOES('UserAgent::Any')) { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | return $ua; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | croak 'Unknown User Agent type "'.ref($ua).'"'; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | __END__ | ||||||||||||||||||||||||||||||||||||||||||