Slackware::Slackget::Network::Message - The response object for Slackware::Slackget::Network class


Slackware-Slackget documentation Contained in the Slackware-Slackget distribution.

Index


Code Index:

NAME

Top

Slackware::Slackget::Network::Message - The response object for Slackware::Slackget::Network class

VERSION

Top

Version 1.0.0

SYNOPSIS

Top

This class is the message object used by the Slackware::Slackget::Network class to return informations from the network connection.

This module is the evolution of the old Slackware::Slackget::Network::Response.

new

the constructor require no argument. But store every given argument in the object (which is a hashref).

	my $msg = new Slackware::Slackget::Network::Message ;

new_from_data

This is an alternative constructor to create a Slackware::Slackget::Network::Message with the whole slack-get protocol compatible data structure.

You must provide the following arguments :

	* an action id (integer)
	* a action (string)
	* some data

Here is a little example :

	my $msg = Slackware::Slackget::Network::Message->new(
		123456789,
		'search',
		@keywords,
	);

create_enveloppe

Create a base enveloppe for the SlackGetProtocol in the raw_data section. This method access directly to the object's data structure.

Be carefull not to use it on an already initialized object. Else all "raw_data" will be lost.

	$self = {
		action => 0,
		action_id => 0,
		raw_data => {
				Enveloppe => {
					Action => {
						id => 0 ,
						content => 0,
					},
					Data => {},
				}
			}
	};

is_success

true if the operation is a success

is_error

true if the operation is an error

error_msg

return a string containing an error message. Works only if $response->is_error() is true.

have_choice

true if the daemon return a choice

data

return all raw data returned by the remote daemon

action

return (or set) the action of the message (all network messages must have an action).

action_id

return (or set) the action ID of the message (all network messages must have an action id).

AUTHOR

Top

DUPUIS Arnaud, <a.dupuis@infinityperl.org>

BUGS

Top

Please report any bugs or feature requests to bug-Slackware-Slackget@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Slackware::Slackget




You can also look for information at:

* Infinity Perl website

http://www.infinityperl.org/category/slack-get

* slack-get specific website

http://slackget.infinityperl.org

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Slackware-Slackget

* CPAN Ratings

http://cpanratings.perl.org/d/Slackware-Slackget

* Search CPAN

http://search.cpan.org/dist/Slackware-Slackget

ACKNOWLEDGEMENTS

Top

Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.

COPYRIGHT & LICENSE

Top


Slackware-Slackget documentation Contained in the Slackware-Slackget distribution.
package Slackware::Slackget::Network::Message ;

use warnings;
use strict;

our $VERSION = '0.9.1';

sub new
{
	my $class = shift;
	my $self = {@_};
	bless($self,$class);
	return $self;
}

sub new_from_data {
	my $class = shift;
	my $action_id = shift;
	my $action = shift;
	my @data = @_;
	my $self = {};
# 	my $self = {
# 		raw_data => {
# 				Enveloppe => {
# 					Action => {
# 						id => $action_id ,
# 						content => $action,
# 					},
# 					Data => {
# 						content => join('',@_),
# 					},
# 				}
# 			}
# 	};
	bless($self,$class);
	$self->create_enveloppe();
	$self->{raw_data}->{Enveloppe}->{Action}->{id} = $action_id;
	$self->{raw_data}->{Enveloppe}->{Action}->{content} = $action;
	$self->{raw_data}->{Enveloppe}->{Data}->{content} = join('',@data);
	return $self;
}

sub create_enveloppe {
	my $self = shift;
	$self->action(0);
	$self->action_id(0);
	$self->{raw_data} =  {
		Enveloppe => {
			Action => {
				id => 0 ,
				content => 0,
			},
			Data => {},
		}
	};
}

sub is_success {
	my $self = shift;
	my $data = shift;
	return $data ? $self->{is_success}=$data : $self->{is_success};
}

sub is_error {
	my $self = shift;
	return !$self->{is_success} ;
}

sub error_msg {
	my $self = shift;
	my $data = shift;
	return $data ? $self->{error_msg}=$data : $self->{error_msg};
}

sub have_choice {
	my $self = shift;
	my $data = shift;
	return $data ? $self->{have_choice}=$data : $self->{have_choice};
}

sub data {
	my $self = shift;
	my $data = shift;
	return $data ? $self->{raw_data}=$data : $self->{raw_data};
}

sub action{
	my $self = shift;
	my $data = shift;
	if($data){
		$self->{raw_data}->{Enveloppe}->{Action}->{content} = $data if(exists($self->{raw_data}->{Enveloppe}->{Action}) && ref($self->{raw_data}->{Enveloppe}->{Action}) eq 'HASH' );
		 $self->{action}=$data
	}else{
		return $self->{action};
	}
}

sub action_id{
	my $self = shift;
	my $data = shift;
	if($data){
		$self->{raw_data}->{Enveloppe}->{Action}->{id} = $data if(exists($self->{raw_data}->{Enveloppe}->{Action}) && ref($self->{raw_data}->{Enveloppe}->{Action}) eq 'HASH' );
		 $self->{action_id}=$data
	}else{
		return $self->{action_id};
	}
}


1; # End of Slackware::Slackget::Network::Message