The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::OBEX::Response::Generic - interpret OBEX protocol generic response packets

SYNOPSIS

    use strict;
    use warnings;
    use Net::OBEX::Response::Generic;

    my $res = Net::OBEX::Response::Generic->new;

    # read 3 bytes of the packet from the socket there somewhere
    # now parse it:
    my $response_ref = $res->parse_info( $data_from_the_socket );

    if ( $response_ref->{headers_length} ) {
        # ok, looks like we got some headers in this packet
        # read $response_ref->{headers_length} bytes from the socket
        # here and parse the headers.
    }

    # OMG SO COMPLICATED!!
    # Why not use Net::OBEX::Response parse_sock() method instead?

DESCRIPTION

WARNING!!! this module is still in early alpha stage. It is recommended that you use it only for testing.

This module is used internally by Net::OBEX::Response and that's what you probably should be using. The module provides means to interpret raw OBEX protocol responses. For parsing Connect responses see Net::OBEX::Response::Connect

CONSTRUCTOR

new

    my $res = Net::OBEX::Response::Generic->new;

Takes no arguments, returns a freshly baked Net::OBEX::Response::Generic object ready to be used and abused.

METHODS

parse_info

    $res->packet( $data_from_wire );
    my $generic_response = $res->parse_info;

    # or

    my $generic_response = $res->parse_info( $data_from_wire );

Takes one optional argument which is the raw data from the wire representing the packet. If called without arguments will use the data which you set via packet() method (see below) Returns a hashref with the following keys/values:

Sample return (descriptions are below):

    $VAR1 = {
        'packet_length' => 3,
        'response_code' => 200,
        'headers_length' => 0,
        'response_code_meaning' => 'OK, Success'
    };

packet_length

    { 'packet_length' => 3 }

The packet_length key will contain the length of the packet in bytes.

headers_length

    { 'headers_length' => 24 }

The headers_length key will contain the length of packet's headers in bytes. You would use this value to finish reading the entire packet from the socket, however, see the parse_sock() method described below.

response_code

    { 'response_code' => 200 }

The response_code key will contain a response code, this will pretty much be HTTP response codes since that what OBEX prefers to use.

response_code_meaning

    { 'response_code_meaning' => 'OK, Success' }

The response_code_meaning key will contain a human parseable explanation of response_code.

code_meaning

    my ( $http_code, $meaning ) = $res->code_meaning( "\xA0" );

Takes one argument which is the byte representing the response code. Returns a list of two elements, the first one is the HTTP code of the response (such as 404) the second element is the human parseable meaning of the code (such as Not Found).

packet

    my $old_packet = $res->packet;

    $res->packet( $new_data_from_the_wire );

Returns a currently set data of the packet. When called with an optional argument will set the current data to parse to whatever you specify in the argument.

info

    my $info_ref = $res->info;

Must be called after a call to parse_info(). Takes no arguments, returns a hashref which is the same as the return value of the last call to parse_info() method. See the description of parse_info() method above for more information.

headers_length

    my $length_of_packet_headers = $res->headers_length;

Must be called after a call to parse_info(). Takes no arguments, returns the length of packet headers in bytes (this is what you still need to read from the socket to get a complete packet). Note: this is the same as the contents of headers_length key of the parse_info() return.

SEE ALSO

Net::OBEX::Packet::Headers, Net::OBEX::Response, Net::OBEX::Response::Connect

REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/Net-OBEX

BUGS

To report bugs or request features, please use https://github.com/zoffixznet/Net-OBEX/issues

If you can't access GitHub, you can email your request to bug-Net-OBEX at rt.cpan.org

AUTHOR

Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)

LICENSE

You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.