NAME
slackget10::Network::Connection - A wrapper for network operation in slack-get
VERSION
Version 0.9.6
SYNOPSIS
This class is anoter wrapper for slack-get. It will encapsulate all nework operation. This class can chang a lot before the release and it may be rename in slackget10::NetworkConnection.
Some words about subclass
This class is a wrapper for subclass like slackget10::Network::Connection::HTTP or slackget10::Network::Connection::FTP. You can add a class for a new protocol (and update this constructor) very simply but you must know that all class the slackget10::Network::Connection::* must have the following methods (the format is : <method name(<arguments>)> : <returned value>, parmameters between [] are optionnals):
- test_server : a float (the server response time)
- fetch_file([$remote_filename],[$local_file]) : a boolean (1 or 0). NOTE: this method store the fetched file on the hard disk. If $local_file is not defined, fetch() must store the file in <update-directory>.
- fetch_all : a boolean (1 or 0)
- get_file([$remote_filename]) : the file content
CONSTRUCTOR
new
use slackget10::Network::Connection;
(1)
my $connection = slackget10::Network::Connection->new('http://www.nymphomatic.org/mirror/linuxpackages/Slackware-10.1/');
my $file = $connection->get_file('FILELIST.TXT');
or :
(2)
my $connection = slackget10::Network::Connection->new('http://www.nymphomatic.org/mirror/linuxpackages/Slackware-10.1/FILELIST.TXT');
my $file = $connection->get_file;
or :
(3)
my $connection = slackget10::Network::Connection->new(
host => 'http://www.nymphomatic.org',
path => '/mirror/linuxpackages/Slackware-10.1/',
files => ['FILELIST.TXT','PACKAGES.TXT','CHECKSUMS.md5'], # Be carefull that it's the files parameter not file. file is the current working file.
config => $config,
mode => 'normal'
);
$connection->fetch_all or die "An error occur during the download\n";
or (the recommended way) :
(4)
my $connection = slackget10::Network::Connection->new(
host => 'http://www.nymphomatic.org',
path => '/mirror/linuxpackages/Slackware-10.1/',
config => $config,
mode => 'normal'
);
my $file = $connection->get_file('FILELIST.TXT') or die "[ERROR] unable to download FILELIST.TXT\n";
or :
my $status = $connection->fetch('FILELIST.TXT',"$config->{common}->{'update-directory'}/".$server->shortname."/cache/FILELIST.TXT");
die "[ERROR] unable to download FILELIST.TXT\n" unless ($status);
The global way (3) is not recommended because of the lake of control on the downloaded file. For example, if there is only 1 download which fail, fetch_all will return undef and you don't know which download have failed.
The simpliest ways (1) and (2) are not recommended because you didn't give a slackget10::Config object to the connection. So you have to manage by yourself all tasks needed to a proper work (like charset encoding, moving file to proper destination, etc.). In this case don't forget that the download methods file save file in the current directory.
The recommended way is to give to the constructor the following arguments :
host : the host (with the protocol, do not provide 'ftp.lip6.fr' provide ftp://ftp.lip6.fr. The protocol will be automatically extract)
path : the path to the working directory on the server (Ex: '/pub/linux/distributions/slackware/slackware-10.1/'). Don't provide a 'file' argument.
config : the slackget10::Config object of the application
mode : a mode between 'normal' or 'secure'. This is only when you attempt to connect to a daemon (front-end/daemon or daemon/daemon connection). 'secure' use SSL connection.
FUNCTIONS
is_url
Take a string as argument and return TRUE (1) if $string is an http or ftp URL and FALSE (0) else
print "$string is a valid URL\n" if($connection->is_url($string)) ;
parse_url
extract the following informations from $url :
- the protocol
- the server
- the file (with its total path)
For example :
$connection->parse_url("ftp://ftp.lip6.fr/pub/linux/distributions/slackware/slackware-current/slackware/n/dhcp-3.0.1-i486-1.tgz");
Will extract :
- protocol = ftp
- host = ftp.lip6.fr
- file = /pub/linux/distributions/slackware/slackware-current/slackware/n/dhcp-3.0.1-i486-1.tgz
This method return TRUE (1) if all goes well, else return FALSE (0)
strip_slash
Remove extra slash (/) in the URL and return the URL.
my $url = $connection->strip_slash('http://ftp.infinityperl.org//slackware-repository////CHECKSUMS.md5') ;
DEBUG_show_data_section
ACCESSORS
All accessors can get or set a value. You can use them like that :
$proto->my_accessor('a value'); # to set the value of the parameter controlled by this accessor
my $value = $proto->my_accessor ; # to get the value of the parameter controlled by this accessor
The common accessors are :
protocol
return the protocol of the current Connection object as a string :
my $proto = $connection->protocol ;
host
return the host of the current Connection object as a string :
my $host = $connection->host ;
file
return the file of the current Connection object as a string :
my $file = $connection->file ;
files
return the list of files of the current Connection object as an array reference :
my $arrayref = $connection->files ;
path
return the path of the current Connection object as a string :
my $path = $connection->path ;
AUTHOR
DUPUIS Arnaud, <a.dupuis@infinityperl.org>
BUGS
Please report any bugs or feature requests to bug-slackget10-networking@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.
ACKNOWLEDGEMENTS
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.