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

NAME

slackget10::Network - A class for network communication

VERSION

Version 0.8.0

SYNOPSIS

WARNING WARNING : this module's API and behaviour changed a lot since the 0.12 release ! Please take good care of this : WARNING WARNING

This class' purpose is to make all network dialog transparent. You give to this class the raw (XML) network message sent to (or from) a slack-get daemon (sg_daemon) and slackget10::Network decode and wrap it for you. The "plus" of this system is that sg_daemon (or any slack-get client) developpers are safe if something change in the network protocol : it will never change the API.

    use slackget10::Network;

    my $net = slackget10::Network->new();
    my $message_object = new slackget10::Network::Message ;
    $message_object->action('get_connection_id');
    my $xml_msg = $net->encode($message_object);
    my $response_object = $net->decode($xml_msg);
    # $message_object and $response_object are equals in term of values

All methods from this module return a slackget10::Network::Message (slackget10::Network::Message) object.

Since the 0.12 release of this module this module is nothing more than a encoder/decoder for slack-get's network messages. So no more network handling nor automatic response sent directly through the socket passed as argument.

CONSTRUCTOR

new

Do not require any parameter. You can optionnally give a backend option with a string :

        my $net = slackget10::Network->new(backend => 'slackget10::Network::Backend::XML');

The only included backend is the XML one for the moment. If the backend could not be loaded the constructor fall back to the XML backend.

FUNCTIONS

All methods return a slackget10::Network::Message (slackget10::Network::Message) object, and if the remote slack-getd return some data they are accessibles via the data() accessor of the slackget10::Network::Message object.

__get_connection_id

Set the id of the connection. The id is generate by the constructor and must not be modified. This method is automatically called by the constructor and is mostly private.

        $net->__get_connection_id ;

__get_installed_list

get the list of installed packages on the remote daemon.

        my $installed_list = $net->get_installed_list ;

If an error occured call the appropriate handler.

In all case return a slackget10::Network::Message (slackget10::Network::Message) object.

__get_packages_list

get the list of new avalaible packages on the remote daemon.

        my $status = $net->get_packages_list ;

If an error occured call the appropriate handler.

In all case return a slackget10::Network::Message (slackget10::Network::Message) object.

__get_html_info

Get an HTML encoded string which give some general information on the remote slack-getd

        print $net->get_html_info ;

__build_packages_list

Said to the remote slack-getd to build the new packages cache.

        my $status = $net->build_packages_list ;

The returned status contains no significant data in case of success.

__build_installed_list

Said to the remote slack-getd to build the installed packages cache.

        my $status = $net->build_installed_list ;

The returned status contains no significant data in case of success.

__build_media_list

Said to the remote slack-getd to build the media list (medias.xml file).

        my $status = $net->build_media_list ;

The returned status contains no significant data in case of success.

__diskspace

Ask to the remote daemon for the state of the disk space on a specify partition.

        $net->handle_responses(1); # We want slackget10::Network handle the response and return the hashref.
        my $response = $net->diskspace( "/" ) ;
        $net->handle_responses(0);
        print "Free space on remote computer / directory is ",$response->data()->{avalaible_space}," KB\n";

Return a slackget10::Network::Message object which contains (in case of success) a HASHREF build like that :

        $space = {
                device => <NUMBER>,
                total_size => <NUMBER>,
                used_space => <NUMBER>,
                available_space => <NUMBER>,
                use_percentage => <NUMBER>,
                mount_point => <NUMBER>
        };

take at least two parameters : the word you search for, and a field. Valid fields are those who describe a package entity in the packages.xml file.

        my $response = $net->search('gcc','name','description') ; # search for package containing 'gcc' in fields 'name' and 'description'

Return the remote slack-getd's response in the DATA section of the response (slackget10::Network::Message).

__websearch

Take 2 parameters : a reference on an array which contains the words to search for, and another array reference which contains a list of fields (valid fields are thoses describe in the packages.xml file).

The DATA section of the response (slackget10::Network::Message) will contain an ARRAYREF. Each cell of this array will contains a package in HTML The returned data is HTML, each package are separed by a line wich only contain the string "__MARK__"

        my $response = $network->websearch([ 'burn', 'cd' ], [ 'name', 'description' ]) ;

__multisearch

Take 2 parameters : a reference on an array which contains the words to search for, and another array reference which contains a list of fields (valid fields are thoses describe in the packages.xml file).

The DATA section of the response (slackget10::Network::Message) will contain the XML encoded response.

        my $response = $network->websearch([ 'burn', 'cd' ], [ 'name', 'description' ]) ;

__getfile

This method allow you to download one or more files from a slack-get daemon. This method of download is specific to slack-get and is based on the EBCS protocol.

Arguments are :

        files : pass a slackget10::PackageList to this option.
        
        destdir : a string wich is the directory where will be stored the downloaded files.

Here is a little code example :

        # $pkgl is a slackget10::PackageList object.
        $net->getfile(
                file => $pkgl,
                destdir => $sgo->config()->{common}->{'update-directory'}."/package-cache/"
        );

__reboot

        This method ask the remote daemon to reboot the remote computer.

__quit

Close the current connection.

        $net->__quit ;

ACCESSORS

slackget (read only)

return the current slackget10 object.

connection_id

Get or set the connection ID.

        $net->connection_id(1234);
        print "Connection ID : ", $net->connection_id , "\n";

handle_responses (read/write)

        Boolean accessor, get/set the value of the handle_responses option.

PKGTOOLS BINDINGS

Methods in this section are the remote call procedure for pkgtools interactions. The slack-getd daemon use another class for direct call to the pkgtools (slackget10::PkgTools).

The 3 methods have the same operating mode :

1) Take a single slackget10::PackageList as argument

2) Do the job

3) If their is more than one choice for the package you try to install, the daemon ask for a choice of you.

3bis) Re-do the job

4) For each package in the slackget10::PackageList set a 'status' field which contain the status of the (install|upgrade|remove) process.

__installpkg

        $net->installpkg($packagelist) ;

__upgradepkg

        $net->upgradepkg($packagelist) ;

__removepkg

Send network commands to a slack-get daemon. This method (like other pkgtools network call), do nothing by herself, but sending a "removepkg:pkg1;pkg2;..;pkgN" to the slack-getd.

        $net->removepkg($packagelist) ;

DEFAULT HANDLERS

Since the 0.12 release there is no more default handlers.

AUTHOR

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

BUGS

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

SUPPORT

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

    perldoc slackget10

You can also look for information at:

ACKNOWLEDGEMENTS

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

SEE ALSO

slackget10::Network::Message, slackget10::Status, slackget10::Network::Connection

COPYRIGHT & LICENSE

Copyright 2005 DUPUIS Arnaud, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.