HTTP-Promise

 view release on metacpan or  search on metacpan

lib/HTTP/Promise/Message.pm  view on Meta::CPAN

        return( $self->error( "Error downgrading utf8 data: $@" ) );
    }
    $rv || return( $self->error( 'HTTP::Promise::Message content must be bytes' ) );
}

sub AUTOLOAD
{
    my( $package, $method ) = $AUTOLOAD =~ m/\A(.+)::([^:]*)\z/;
    my $code = $_[0]->can( $method );
    goto( &$code ) if( $code );
    # Give a chance to our parent AUTOLOAD to kick in
    $Module::Generic::AUTOLOAD = $AUTOLOAD;
    goto( &Module::Generic::AUTOLOAD );
}

# sub CARP_TRACE { return( shift->_get_stack_trace ); }

# avoid AUTOLOADing it
sub DESTROY { }

# NOTE: sub FREEZE is inherited

sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }

sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }

# NOTE: sub THAW is inherited
sub THAW
{
    my( $self, $serialiser, @args ) = @_;
    my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
    my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
    my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
    my $new;
    # Storable pattern requires to modify the object it created rather than returning a new one
    if( CORE::ref( $self ) )
    {
        foreach( CORE::keys( %$hash ) )
        {
            $self->{ $_ } = CORE::delete( $hash->{ $_ } );
        }
        
        # Need to make sure the headers object, which is an XS one is properly post processed, because Storable does not handle well XS objects, as of version 3.26
        if( CORE::exists( $self->{headers} ) && 
            CORE::defined( $self->{headers} ) && 
            CORE::ref( $self->{headers} ) && 
            $self->{headers}->isa( 'HTTP::Promise::Headers' ) )
        {
            $self->{headers} = $self->{headers}->STORABLE_thaw_post_processing;
        }
        # The headers object in HTTP::Promise::Message must be the same shared on in HTTP::Promise::Entity
        if( CORE::exists( $self->{entity} ) &&
            CORE::exists( $self->{entity}->{headers} ) )
        {
            $self->{entity}->{headers} = $self->{headers};
        }
        $new = $self;
    }
    else
    {
        $new = bless( $hash => $class );
    }
    CORE::return( $new );
}

# NOTE: only here to avoid triggering HTTP::Promise::Headers::STORABLE_thaw_post_processing which we inherit when we did 'require HTTP::Promise::Headers'
sub STORABLE_thaw_post_processing { CORE::return( $_[0] ); }

1;
# NOTE: POD
__END__

=encoding utf-8

=head1 NAME

HTTP::Promise::Message - HTTP Message Class

=head1 SYNOPSIS

    use HTTP::Promise::Message;
    my $this = HTTP::Promise::Message->new(
        [ 'Content-Type' => 'text/plain' ],
        'Hello world'
    ) || die( HTTP::Promise::Message->error, "\n" );

=head1 VERSION

    v0.3.0

=head1 DESCRIPTION

This class represents an HTTP message, and implements methods that are common to either a request or a response. This class is inherited by L<HTTP::Promise::Request> and L<HTTP::Promise::Response>. It difffers from L<HTTP::Promise::Entity> in that L<...

Here is how it fits in overall relation with other classes.
                                                               
    +-------------------------+    +--------------------------+    
    |                         |    |                          |    
    | HTTP::Promise::Request  |    | HTTP::Promise::Response  |    
    |                         |    |                          |    
    +------------|------------+    +-------------|------------+    
                 |                               |                 
                 |                               |                 
                 |                               |                 
                 |  +------------------------+   |                 
                 |  |                        |   |                 
                 +--- HTTP::Promise::Message |---+                 
                    |                        |                     
                    +------------|-----------+                     
                                 |                                 
                                 |                                 
                    +------------|-----------+                     
                    |                        |                     
                    | HTTP::Promise::Entity  |                     
                    |                        |                     
                    +------------|-----------+                     
                                 |                                 
                                 |                                 
                    +------------|-----------+                     
                    |                        |                     
                    | HTTP::Promise::Body    |                     

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.641 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )