| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Pool.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2022/03/27 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2023/09/08 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved. | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | package HTTP::Promise::Pool; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | warnings::register_categories( 'HTTP::Promise' ); | |||||||||||||||||||||||||||
| 20 | 2 | ▶ | use parent qw( Module::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 2 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||
| 28 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 2 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 30 | 2 | $self->{host} = undef; | |||||||||||||||||||||||||||
| 31 | 2 | $self->{port} = undef; | |||||||||||||||||||||||||||
| 32 | 2 | $self->{sock} = undef; | |||||||||||||||||||||||||||
| 33 | 2 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||
| 34 | 2 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | return( $self ); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub host { return( shift->_set_get_scalar_as_object( 'host', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub host_port | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
host_port: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $host = $self->host || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->host || ''
MC/DC0%0/1
$self->host || ''
$self->host
Truth table0%0/2
A
A= $self->host
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $port = $self->port || ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->port || ''
MC/DC0%0/1
$self->port || ''
$self->port
Truth table0%0/2
A
A= $self->port
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | return( join( ':', $host, $port ) ) if( length( $host ) && length( $port ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $host and length $port
MC/DC0%0/2
length $host and length $port
length $host
length $port
Truth table0%0/3
A and B
A= length $hostB= length $port
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return( $host ) if( length( $host ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | return; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub port { return( shift->_set_get_number( 'port', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
port: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub push | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
push: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 55 | 0 | my( $host, $port, $sock ) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | $self->host( $host ); | |||||||||||||||||||||||||||
| 57 | 0 | $self->port( $port ); | |||||||||||||||||||||||||||
| 58 | 0 | $self->sock( $sock ); | |||||||||||||||||||||||||||
| 59 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub reset | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 65 | 0 | $self->{host} = undef; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{port} = undef; | |||||||||||||||||||||||||||
| 67 | 0 | return( $self ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub sock { return( shift->_set_get_scalar( 'sock', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
sock: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub steal | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
steal: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||
| 75 | 0 | my( $host, $port ) = @_; | |||||||||||||||||||||||||||
| 76 | 0 | my $host_port = $self->host_port; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if( defined( $host_port ) && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $host_port and $host_port eq "${host}:$port"
MC/DC0%0/2
defined $host_port and $host_port eq "${host}:$port"
defined $host_port
$host_port eq "${host}:$port"
Truth table0%0/3
A and B
A= defined $host_portB= $host_port eq "${host}:$port"
| |||||||||||||||||||||||||||||
| 78 | $host_port eq "${host}:${port}" ) | ||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||
| 80 | 0 | my $sock = $self->sock; | |||||||||||||||||||||||||||
| 81 | 0 | $self->reset; | |||||||||||||||||||||||||||
| 82 | 0 | return( $sock ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | else | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 0 | return; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub FREEZE | ||||||||||||||||||||||||||||
| 91 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
FREEZE: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 2 | my $self = CORE::shift( @_ ); | |||||||||||||||||||||||||||
| 93 | 2 | ▶ | my $serialiser = CORE::shift( @_ ) // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift @_ // ""
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 94 | 2 | my $class = CORE::ref( $self ); | |||||||||||||||||||||||||||
| 95 | 2 | my %hash = %$self; | |||||||||||||||||||||||||||
| 96 | 2 | CORE::delete( @hash{ qw( sock ) } ); | |||||||||||||||||||||||||||
| 97 | # Return an array reference rather than a list so this works with Sereal and CBOR | ||||||||||||||||||||||||||||
| 98 | 2 | ▶ | CORE::return( [$class, \%hash] ) if( $serialiser eq 'Sereal' || $serialiser eq 'CBOR' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$serialiser eq "Sereal" or $serialiser eq "CBOR"
MC/DC50%1/2
$serialiser eq "Sereal" or $serialiser eq "CBOR"
$serialiser eq "Sereal"
$serialiser eq "CBOR"
Truth table66%2/3
A or B
A= $serialiser eq "Sereal"B= $serialiser eq "CBOR"
| |||||||||||||||||||||||||||||
| 99 | # But Storable want a list with the first element being the serialised element | ||||||||||||||||||||||||||||
| 100 | 1 | CORE::return( $class, \%hash ); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 1 | ▶ | sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_freeze: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
STORABLE_thaw: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # NOTE: sub THAW is inherited | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | 1; | |||||||||||||||||||||||||||
| 110 | # NOTE: POD | ||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||