RoPkg::Utils(3pm) | User Contributed Perl Documentation | RoPkg::Utils(3pm) |
NAME¶
RoPkg::Utils - general pourpose class.VERSION¶
0.4.6DESCRIPTION¶
RoPkg::Utils is a collection of methods used by all other modules in RoPkg.SYNOPSIS¶
#!/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();
When we run this, we have:
01 001 001 Could not create /tmp.xyz Permission denied
SUBROUTINES/METHODS¶
- 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)
- *) Param::Missing when a required parameter is not found in the parameters list.
- *) Param::Wrong when a parameter does not comply with the rules. For example when a method expects a number and finds a string.
Methods details¶
RoPkg::Utils exports all the methods from the above list. Of course, you can select which ones you want to import. Example:use RoPkg::Utils qw(ZeroPad);
sub main { print ZeroPad(1, 3),$/; }
main();
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(1, 2) => 01
ZeroPad(12, 5) => 00012
ZeroPad(-3, 4) => -003
ZeroPad(10, 2) => 10
GetMonthNo('Jan') => 1
GetMonthNo('Jan', 2) => 01
GetMonthNo('January') => 1
GetMonthNo('January', 2) => 01
ElemInList(1, qw(1 2 3 4)) => 1
ElemInList(1, qw(2 3 4)) => 0
GetHumanDate(12345678) => '1970/05/23 23:21'
SecToTime(3) => 00:00:03
SecToTime(61) => 00:01:01
AddSlash('mydirectory') => 'mydirectory/'
AddSlash('/tmp/') => '/tmp/';
DelSlash('/tmp/') => '/tmp'
DelSlash('/tmp//') => '/tmp/'
my $uri = 'http://www.packages.ro//test///uri'; $uri = CleanURI($uri); print $uri,$RS;
the result is: http://www.packages.ro/test/uriCleanURI recognise only ftp,http and rsync uri's . Any other uri is ignored
my $path = '/var/ftp/mirrors///pub//debian.org//'; $path = CleanPath($path); print $path, $RS;
the result is: /var/ftp/mirrors/pub/debian.org/
DEPENDENCIES¶
RoPkg::Utils requires perl 5.008 or later and the following modules:- Test::More
- Test::Pod::Coverage
- Exception::Class >= 1.21
- Scalar::Util
- Exporter
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.INCOMPATIBILITIES¶
None known to the authorBUGS AND LIMITATIONS¶
None known to the authorPERL CRITIC¶
The code for this module is perl critic level 2 compliantSEE ALSO¶
RoPkg::ExceptionsAUTHOR¶
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.2006-06-09 | perl v5.8.8 |