RoPkg::Utils(3pm)
πΈ NAME πΈ
okay bestie, welcome to RoPkg::Utils β this is the RoPkg::Utils(3pm) page, and it's literally the general pourpose class. She's the friend that everyone in the RoPkg group chat relies on. π
β¨ VERSION β¨
0.4.6 β that's the version, no cap. π
π¦ DESCRIPTION π¦
RoPkg::Utils is a collection of methods used by all the other modules in RoPkg. She's the communal glue, the group-chat admin, the one who actually has her life together. π«Ά
π SYNOPSIS π
here's the vibe in code form, copy it, love it, run it:
#!/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('/tmp.xyz', 'test message');
};
if (my $e = Exception::Class->caught('File::Create')) {
print $e->message,$/;
exit(1);
}
return 0;
}
main();
and when we run this, we have:
01
001
001
Could not create /tmp.xyz
Permission denied
iconic. she said "I'll make you a file" and the OS said "absolutely not" π
π SUBROUTINES/METHODS π
the whole roster, the full squad, everybody on the list:
new()CheckParam($object, @param_list)ZeroPad($number, $pad_length)GetMonthNo($month_name, $padding)ElemInList($element_name, @element_list)GetHumanDate($timestamp)SecToTime($seconds)AddSlash($text)DelSlash($text)CreateFile($file_path, $content)ReadFile($file_path)CleanURI($uri)CleanPath($path)GetMD5($path)
π heads up bestie: all methods raise the following exceptions: -Param::Missingwhen a required parameter is not found in the parameters list. -Param::Wrongwhen a parameter does not comply with the rules. For example when a method expects a number and finds a string.
besides these exceptions, each method might raise some specific exceptions (peep CreateFile for one of those). new() is provided for OO. It doesn't do anything special, besides the blessing. she's just standing there, blessed, doing nothing. main character energy fr fr. β¨
π Methods details π
RoPkg::Utils exports all the methods from the above list. Of course, you can select which ones you want to import. choosey bestie behavior, we respect it.
Example:
use RoPkg::Utils qw(ZeroPad);
sub main {
print ZeroPad(1, 3),$/;
}
main();
πΈ CheckParam πΈ
Check if the parameters from the list are defined inside the object. If the parameters are not defined Param::Missing exception is raised. she does a little vibe check on your params and if they ghosted, she screams. π
Example
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;
π 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 $number and $pad_length. The $number is the number who is going to be padded, $pad_length is the maximum length. Zeroes are added until $pad_length is reached. If $pad_length is not defined, length($number)+1 is used. If $pad_length is less than number length, no padding is done. periodt, she respects boundaries.
ZeroPad(1, 2) => 01
ZeroPad(12, 5) => 00012
ZeroPad(-3, 4) => -003
ZeroPad(10, 2) => 10
π¦ 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: $month_name and $padding. $month_name must be January .. December or Jan .. Dec. If the month_name is not found, Param::Unknown exception is raised. $padding is used to pad the numeric index of the month. When padding is not defined, no padding is made.
GetMonthNo('Jan') => 1
GetMonthNo('Jan', 2) => 01
GetMonthNo('January') => 1
GetMonthNo('January', 2) => 01
π 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. is she in the group chat or not, that's the whole question. π
ElemInList(1, qw(1 2 3 4)) => 1
ElemInList(1, qw(2 3 4)) => 0
π GetHumanDate π
Converts the timestamp to YYYY/MM/DD HH:MM format.
GetHumanDate(12345678) => '1970/05/23 23:21'
π§ SecToTime π§
Converts the seconds to <x days> HH:MM:SS format.
SecToTime(3) => 00:00:03
SecToTime(61) => 00:01:01
πΈ AddSlash πΈ
Adds a slash at the end of the string, if the slash is not present. Othewise, leaves the string untouched.
AddSlash('mydirectory') => 'mydirectory/'
AddSlash('/tmp/') => '/tmp/';
π 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. one slash at a time, she's not doing a whole sweep. π
DelSlash('/tmp/') => '/tmp'
DelSlash('/tmp//') => '/tmp/'
π CreateFile π
Creates a file (with the filename specified), and optionally set the content of the file to the one specified by $content variable. If $content is not defined, the file is just created. If the file can't be created File::Create exception is raised. Returns 1 upon success.
π₯ this is the one that raises her own extra exception, remember the synopsis? yeah. she tries her best and sometimes the permissions say no. π
π ReadFile π
Reads the content of the specified file into a variable. If the file can't be opened a File::Open exception is raised. On success returns the file content or !defined if the file is empty. (yes, she said !defined. lowkey giving perl-brain but we love her. π«Ά)
π¦ CleanURI($uri) π¦
Cleans the $uri from the excedent / -es .
Example:
my $uri = 'http://www.packages.ro//test///uri';
$uri = CleanURI($uri);
print $uri,$RS;
the result is:
http://www.packages.ro/test/uri
CleanURI recognise only ftp,http and rsync uri's . Any other uri is ignored. if your scheme isn't on the list, she's simply not looking. π
β¨ CleanPath($path) β¨
Cleans the $path from the excedent / -es .
Example:
my $path = '/var/ftp/mirrors///pub//debian.org//';
$path = CleanPath($path);
print $path, $RS;
the result is:
/var/ftp/mirrors/pub/debian.org/
π GetMD5($path) π
Returns the base64 md5 sum for the specified file.
π DEPENDENCIES π
RoPkg::Utils requires perl 5.008 or later and the following modules:
Test::MoreTest::Pod::CoverageException::Class >= 1.21Scalar::UtilExporter
β DIAGNOSTICS β
To run the tests for this module, unpack the source and use 'make test' command to run the tests.
π«Ά CONFIGURATION AND ENVIRONMENT π«Ά
This module does not use any configuration files or environment variables. she's low maintenance, no settings, no env drama, she just is. π§
π INCOMPATIBILITIES π
None known to the author
π BUGS AND LIMITATIONS π
None known to the author
π PERL CRITIC π
The code for this module is perl critic level 2 compliant. clean code queen, we stan. π
π SEE ALSO π
RoPkg::Exceptions
πΈ AUTHOR πΈ
Subredu Manuel <diablo@iasi.roedu.net>
π 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 LICENSE file contains the full text of the license.
okay that's the whole page bestie, you ate it, go forth and pad some zeroes π β¨
signing off with love: this was perl v5.32.1, dated 2021-12-26, from your girl RoPkg::Utils(3pm). mwah. π«Άπ
π¦ where this page comes from
- ubuntu jammy: libropkg-perl 0.4-1.4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms