.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "RoPkg::Utils 3pm" .TH RoPkg::Utils 3pm "2021-12-26" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" RoPkg::Utils \- general pourpose class. .SH "VERSION" .IX Header "VERSION" 0.4.6 .SH "DESCRIPTION" .IX Header "DESCRIPTION" RoPkg::Utils is a collection of methods used by all other modules in RoPkg. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& #!/usr/bin/perl \& \& use strict; \& use warnings; \& \& use RoPkg::Utils; \& \& sub main { \& my $u = new RoPkg::Utils; \& \& print $u\->ZeroPad(1),$/, \& $u\->ZeroPad(1, 3),$/, \& RoPkg::Utils::ZeroPad(1, 3),$/; \& \& eval { \& $u\->CreateFile(\*(Aq/tmp.xyz\*(Aq, \*(Aqtest message\*(Aq); \& }; \& \& if (my $e = Exception::Class\->caught(\*(AqFile::Create\*(Aq)) { \& print $e\->message,$/; \& exit(1); \& } \& \& return 0; \& } \& \& main(); \& \& When we run this, we have: \& \& 01 \& 001 \& 001 \& Could not create /tmp.xyz \& Permission denied .Ve .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .IP "\fBnew()\fR" 12 .IX Item "new()" .PD 0 .ie n .IP "CheckParam($object, @param_list)" 12 .el .IP "CheckParam($object, \f(CW@param_list\fR)" 12 .IX Item "CheckParam($object, @param_list)" .ie n .IP "ZeroPad($number, $pad_length)" 12 .el .IP "ZeroPad($number, \f(CW$pad_length\fR)" 12 .IX Item "ZeroPad($number, $pad_length)" .ie n .IP "GetMonthNo($month_name, $padding)" 12 .el .IP "GetMonthNo($month_name, \f(CW$padding\fR)" 12 .IX Item "GetMonthNo($month_name, $padding)" .ie n .IP "ElemInList($element_name, @element_list)" 12 .el .IP "ElemInList($element_name, \f(CW@element_list\fR)" 12 .IX Item "ElemInList($element_name, @element_list)" .IP "GetHumanDate($timestamp)" 12 .IX Item "GetHumanDate($timestamp)" .IP "SecToTime($seconds)" 12 .IX Item "SecToTime($seconds)" .IP "AddSlash($text)" 12 .IX Item "AddSlash($text)" .IP "DelSlash($text)" 12 .IX Item "DelSlash($text)" .ie n .IP "CreateFile($file_path, $content)" 12 .el .IP "CreateFile($file_path, \f(CW$content\fR)" 12 .IX Item "CreateFile($file_path, $content)" .IP "ReadFile($file_path)" 12 .IX Item "ReadFile($file_path)" .IP "CleanURI($uri)" 12 .IX Item "CleanURI($uri)" .IP "CleanPath($path)" 12 .IX Item "CleanPath($path)" .IP "GetMD5($path)" 12 .IX Item "GetMD5($path)" .PD .PP All methods raise the following exceptions: .IP "*) \fBParam::Missing\fR when a required parameter is not found in the parameters list." 2 .IX Item "*) Param::Missing when a required parameter is not found in the parameters list." .PD 0 .IP "*) \fBParam::Wrong\fR when a parameter does not comply with the rules. For example when a method expects a number and finds a string." 2 .IX Item "*) Param::Wrong when a parameter does not comply with the rules. For example when a method expects a number and finds a string." .PD .PP Besides these exceptions, each method might raise some specific exceptions (see \fICreateFile\fR). \fI\f(BInew()\fI\fR is provided for \s-1OO.\s0 It doesn't do anything special, besides the blessing. .SH "Methods details" .IX Header "Methods details" RoPkg::Utils exports all the methods from the above list. Of course, you can select which ones you want to import. .PP \fIExample:\fR .IX Subsection "Example:" .PP .Vb 1 \& use RoPkg::Utils qw(ZeroPad); \& \& sub main { \& print ZeroPad(1, 3),$/; \& } \& \& main(); .Ve .SS "CheckParam" .IX Subsection "CheckParam" Check if the parameters from the list are defined inside the object. If the parameters are not defined Param::Missing exception is raised. .PP \fIExample\fR .IX Subsection "Example" .PP .Vb 1 \& package RoPkg::TesterPkg; \& \& sub new { \& my ($class, %opt) = @_; \& my $self; \& \& $self = bless { %opt }, $class; \& \& $self\->_test_options_1(); \& $self\->_test_options_2(); \& \& return $self; \& } \& \& sub _test_options_1 { \& my ($self) = @_; \& \& RoPkg::Utils::CheckParam($self, qw(dbo dbo_method)); \& \& return 1; \& } \& \& sub _test_options_2 { \& my ($self) = @_; \& my $ru; \& \& $ru = new RoPkg::Utils; \& $ru\->CheckParam($self, qw(dbo dbo_method)); \& \& return 1; \& } \& \& 1; .Ve .SS "ZeroPad" .IX Subsection "ZeroPad" This method is usefull when you need to pad with zeroes some numbers. For the moment positive and negative numbers are suported (only integer ones). This method takes 2 parameters \fB\f(CB$number\fB\fR and \fB\f(CB$pad_length\fB\fR. The \fB\f(CB$number\fB\fR is the number who is going to be padded, \fB\f(CB$pad_length\fB\fR is the maximum length. Zeroes are added until \f(CW$pad_length\fR is reached. If \f(CW$pad_length\fR is not defined, length($number)+1 is used. If \f(CW$pad_length\fR is less than number length, no padding is done. Ex: ZeroPad(1, 2) => 01 ZeroPad(12, 5) => 00012 ZeroPad(\-3, 4) => \-003 ZeroPad(10, 2) => 10 .SS "GetMonthNo" .IX Subsection "GetMonthNo" Used to find a month numeric index (1..12). For the moment full month names and short month names (first 3 letters) are supported. 2 parameters may be passed to this method: \fB\f(CB$month_name\fB\fR and \fB\f(CB$padding\fB\fR. \f(CW$month_name\fR must be January .. December or Jan .. Dec . If the month_name is not found, Param::Unknown exception is raised. \f(CW$padding\fR is used to pad the numeric index of the month. When padding is not defined, no padding is made. Ex: GetMonthNo('Jan') => 1 GetMonthNo('Jan', 2) => 01 GetMonthNo('January') => 1 GetMonthNo('January', 2) => 01 .SS "ElemInList" .IX Subsection "ElemInList" Takes two parameters. A element value and a list of elements. The methods, search the element value within the list. Returns 1 if the element was found, 0 otherwise. Ex: ElemInList(1, qw(1 2 3 4)) => 1 ElemInList(1, qw(2 3 4)) => 0 .SS "GetHumanDate" .IX Subsection "GetHumanDate" Converts the timestamp to \s-1YYYY/MM/DD HH:MM\s0 format. Ex: GetHumanDate(12345678) => '1970/05/23 23:21' .SS "SecToTime" .IX Subsection "SecToTime" Converts the seconds to \s-1HH:MM:SS\s0 format. Ex: \fBSecToTime\fR\|(3) => 00:00:03 SecToTime(61) => 00:01:01 .SS "AddSlash" .IX Subsection "AddSlash" Adds a slash at the end of the string, if the slash is not present. Othewise, leaves the string untouched. Ex: AddSlash('mydirectory') => 'mydirectory/' AddSlash('/tmp/') => '/tmp/'; .SS "DelSlash" .IX Subsection "DelSlash" Removes the slash from the end of the string. If the string has multiple slashes, only the last one is removed. If the string doesn't have any slashes at the end, no modification is made. Ex: DelSlash('/tmp/') => '/tmp' DelSlash('/tmp//') => '/tmp/' .SS "CreateFile" .IX Subsection "CreateFile" Creates a file (with the filename specified), and optionally set the content of the file to the one specified by \f(CW$content\fR variable. If \f(CW$content\fR is not defined, the file is just created. If the file can't be created \fIFile::Create\fR exception is raised. Returns 1 upon success. .SS "ReadFile" .IX Subsection "ReadFile" Reads the content of the specified file into a variable. If the file can't be opened a \fIFile::Open\fR exception is raised. On success returns the file content or !defined if the file is empty. .SS "CleanURI($uri)" .IX Subsection "CleanURI($uri)" Cleans the \f(CW$uri\fR from the excedent / \-es . .PP \fIExample:\fR .IX Subsection "Example:" .PP .Vb 3 \& my $uri = \*(Aqhttp://www.packages.ro//test///uri\*(Aq; \& $uri = CleanURI($uri); \& print $uri,$RS; \& \& the result is: \& http://www.packages.ro/test/uri .Ve .PP CleanURI recognise only ftp,http and rsync uri's . Any other uri is ignored .SS "CleanPath($path)" .IX Subsection "CleanPath($path)" Cleans the \f(CW$path\fR from the excedent / \-es . .PP \fIExample:\fR .IX Subsection "Example:" .PP .Vb 3 \& my $path = \*(Aq/var/ftp/mirrors///pub//debian.org//\*(Aq; \& $path = CleanPath($path); \& print $path, $RS; \& \& the result is: \& /var/ftp/mirrors/pub/debian.org/ .Ve .SS "GetMD5($path)" .IX Subsection "GetMD5($path)" Returns the base64 md5 sum for the specified file. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" RoPkg::Utils requires perl 5.008 or later and the following modules: .IP "Test::More" 5 .IX Item "Test::More" .PD 0 .IP "Test::Pod::Coverage" 5 .IX Item "Test::Pod::Coverage" .IP "Exception::Class >= 1.21" 5 .IX Item "Exception::Class >= 1.21" .IP "Scalar::Util" 5 .IX Item "Scalar::Util" .IP "Exporter" 5 .IX Item "Exporter" .PD .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" To run the tests for this module, unpack the source and use 'make test' command to run the tests. .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" This module does not use any configuration files or environment variables. .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" None known to the author .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" None known to the author .SH "PERL CRITIC" .IX Header "PERL CRITIC" The code for this module is perl critic level 2 compliant .SH "SEE ALSO" .IX Header "SEE ALSO" RoPkg::Exceptions .SH "AUTHOR" .IX Header "AUTHOR" Subredu Manuel .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" Copyright (C) 2005 Subredu Manuel. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The \s-1LICENSE\s0 file contains the full text of the license.