Slackware::Slackget::Status - A class for returning a status code with its explanations
Version 1.0.100
This class is used at a status object which can tell more informations to user. In this object are stored couples of integer (the return code of the function which return the status object), and string (the human readable description of the error)
use Slackware::Slackget::Status; my $status = Slackware::Slackget::Status->new( codes => { 0 => "All operations goes well", 1 => "Parameters unexpected", 2 => "Network error" } ); print "last error message was: ",$status->to_string,"\n"; if($status->is_error) { die "Error: ",$status->to_string,"\n"; } elsif($status->is_success) { print $status->to_string,"\n"; }
Please note that you must see at the documentation of a class to know the returned codes.
You need to pass to the constructor a parameter 'codes' wich contain a hashref with number return code as keys and explanation strings as values :
my $status = new Slackware::Slackget::Status ( codes => { 0 => "All good\n", 1 => "Network unreachable\n", 2 => "Host unreachable\n", 3 => "Remote file seems not exist\n" } );
You can, optionnally, give to more parameters : success_codes and error_codes within the same format than codes. It'll allow you to control the current status via the is_success() and is_error() methods.
Return the explanation string of the current status.
if($connection->fetch_file($remote_file,$local_file) > 0) { print "ERROR : ",$status->to_string ; return undef; } else { ... }
Same as to_string but return the code number.
Same as to_xml(), provided for backward compatibility.
return an xml ecoded string, represented the current status. The XML string will be like that :
<status code="0" description="All goes well" /> $xml_file->Add($status->to_xml) ;
Same as to_html(), provided for backward compatibility.
return the status as an HTML encoded string
Called wihtout argument, just call to_int(), call with an integer argument, set the current status code to this int.
my $code = $status->current ; # same effect as my $code = $status->to_int ; or $status->current(12);
Warning : call current() with a non-integer argument will fail ! The error code MUST BE AN INTEGER.
return true (1) if the current() code is declared as a success code (constructor's parameter: success_codes). Return false otherwise (particularly if you have only set codes and not success_codes).
return true (1) if the current() code is declared as an error code (constructor's parameter: error_codes). Return false otherwise (particularly if you have only set codes and not error_codes).
DUPUIS Arnaud, <a.dupuis@infinityperl.org>
<a.dupuis@infinityperl.org>
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.
bug-Slackware-Slackget@rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Slackware::Slackget::Status
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
Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation.
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.
To install Slackware::Slackget, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Slackware::Slackget
CPAN shell
perl -MCPAN -e shell install Slackware::Slackget
For more information on module installation, please visit the detailed CPAN module installation guide.