NAME

slackget10::Network - A class for network communication

VERSION

Version 1.0.0

SYNOPSIS

This class' purpose is to make all network dialog transparent. Instead of sending

    use slackget10::Network;

    my $net = slackget10::Network->new(
        socket => IO::Socket::INET->new(
                PeerAddr => 192.168.0.10,
                PeerPort => 42000)
    );
    my $installed = $net->get_installed_list ;
    my $reponse = $net->install_packages("gcc-objc;gcc-g++;gcc");
    if($response->is_success)
    {
        print "Packages successfully installed\n";
    }
    elsif($response->have_choice)
    {
        print $response->data ;
    }
    elsif($response->is_error)
    {
        print "An error occured during install. Remote daemon said : ",$response->data ,"\n";
    }

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

In the same way they all handle network exceptions from remote daemon.

CONSTRUCTOR

new

Need a 'socket' argument :

    my $net = slackget10::Network->new(
        socket => IO::Socket::INET->new(
                PeerAddr => 192.168.0.10,
                PeerPort => 42000)
    );

The constructor can take the followings arguments :

socket : a IO::Socket::INET wich is connected to the remote slack-getd

slackget_object : a reference to a valide slackget10 object.

on_error [handler] : a CODE reference to a sub which will be call on each error message returned by the server. This sub must take a string (the error message) as argument.

on_success [handler] : a CODE reference to a sub which will be call on each success message returned by the server. This sub must take a string (the error message) as argument.

on_unknow [handler] : a CODE reference to a sub which will be call on each unknown command message returned by the remote slack-getd. This sub must take a string (the error message) as argument.

on_choice [handler] : a CODE reference to a sub wich will be call each time a choice is needed. This sub must take a reference to an array as first argument and the whole XML string which represent the choice as second argument. The arrayref is where the treatment method will put the result of the choice. Please look at the source code of the on_choice method for more informations.

There is also one special event : 'end' which is not hookable. It may be in the futur but this event is send when all treatment and data relative to the last command are terminate (but there is no information about the state in this event). It seems that this is usefull only to this module's methods.

Look at the "DEFAULT HANDLERS" section for more informations one default handlers.

FUNCTIONS

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

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::Response (slackget10::Network::Response) 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::Response (slackget10::Network::Response) 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_server_list

Said to the remote slack-getd to build the server list (servers.xml file).

        my $status = $net->build_server_list ;

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

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::Response).

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::Response) 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' ]) ;

Host

Call the peerhost() method of the current IO::Socket::INET object and return the result.

ACCESSORS

Socket

return the current socket (IO::Socket::INET) object.

slackget

return the current slackget10 object.

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

removepkg

quit

Close the current connection.

        $net->quit ;

DEFAULT HANDLERS

on_success

Just print on standard error output the success message.

THIS FUNCTION CANNOT BE CALL AS AN INSTANCE METHOD

on_error

Just print on standard error output the error message.

THIS FUNCTION CANNOT BE CALL AS AN INSTANCE METHOD

on_unknow

Just print on standard error output an error message with the unknown command.

THIS FUNCTION CANNOT BE CALL AS AN INSTANCE METHOD

on_choice

Default handle for on_choice event. This handler is not really suitable because she automatically choose the first package of the list.

THIS FUNCTION CANNOT BE CALL AS AN INSTANCE METHOD

on_info

Just print on standard output the info message wich have been receive.

THIS FUNCTION CANNOT BE CALL AS AN INSTANCE METHOD

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.

SEE ALSO

slackget10::Network::Response, 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.