Imported Upstream version 0.03
This commit is contained in:
commit
6377f67204
11
Changes
Normal file
11
Changes
Normal file
@ -0,0 +1,11 @@
|
||||
Revision history for Perl extension Data::Random::String.
|
||||
|
||||
0.03 Mon Jan 5 11:55:00 2007
|
||||
- Removed constraint of Perl 5.8.8 since the module works with previous versions of Perl (thanks to David Betz for testing the module in earlier version of Perl)
|
||||
|
||||
0.02 Mon Jan 1 11:08:00 2007
|
||||
- Pod documentation updates in String.pm
|
||||
|
||||
0.01 Thu Dec 28 15:43:52 2006
|
||||
- Initial release.
|
||||
|
10
MANIFEST
Normal file
10
MANIFEST
Normal file
@ -0,0 +1,10 @@
|
||||
Changes
|
||||
MANIFEST
|
||||
META.yml # Will be created by "make dist"
|
||||
Makefile.PL
|
||||
README
|
||||
lib/Data/Random/String.pm
|
||||
t/00-load.t
|
||||
t/boilerplate.t
|
||||
t/pod-coverage.t
|
||||
t/pod.t
|
19
META.yml
Normal file
19
META.yml
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Data-Random-String
|
||||
version: 0.03
|
||||
author:
|
||||
- 'Ioakim (Makis) Marmaridis <m.marmaridis@gmail.com>'
|
||||
abstract: This is a module for generating random strings
|
||||
license: perl
|
||||
resources:
|
||||
license: http://dev.perl.org/licenses/
|
||||
build_requires:
|
||||
Test::More: 0
|
||||
provides:
|
||||
Data::Random::String:
|
||||
file: lib/Data/Random/String.pm
|
||||
version: 0.03
|
||||
generated_by: Module::Build version 0.2806
|
||||
meta-spec:
|
||||
url: http://module-build.sourceforge.net/META-spec-v1.2.html
|
||||
version: 1.2
|
16
Makefile.PL
Normal file
16
Makefile.PL
Normal file
@ -0,0 +1,16 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
NAME => 'Data::Random::String',
|
||||
AUTHOR => 'Ioakim (Makis) Marmaridis <m.marmaridis@gmail.com>',
|
||||
VERSION_FROM => 'lib/Data/Random/String.pm',
|
||||
ABSTRACT_FROM => 'lib/Data/Random/String.pm',
|
||||
PL_FILES => {},
|
||||
PREREQ_PM => {
|
||||
'Test::More' => 0,
|
||||
},
|
||||
dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
|
||||
clean => { FILES => 'Data-Random-String-*' },
|
||||
);
|
32
README
Normal file
32
README
Normal file
@ -0,0 +1,32 @@
|
||||
Data-Random-String version 0.03
|
||||
===============================
|
||||
|
||||
This module implements a simple method for generating random text
|
||||
strings that can be used in a variety of applications.
|
||||
|
||||
I make no claim of this module being able to generate unique
|
||||
strings, just random. If you need to generate truly unique
|
||||
identifies you may like to look at Data::UUID or better still
|
||||
Data::GUID.
|
||||
|
||||
|
||||
INSTALLATION
|
||||
|
||||
To install this module type the following:
|
||||
|
||||
perl Makefile.PL
|
||||
make
|
||||
make test
|
||||
make install
|
||||
|
||||
DEPENDENCIES
|
||||
|
||||
None.
|
||||
|
||||
COPYRIGHT AND LICENCE
|
||||
|
||||
Copyright (C) 2006, Ioakim (Makis) Marmaridis
|
||||
|
||||
This library is free software; you can redistribute it
|
||||
and/or modify it under the same terms as Perl itself.
|
||||
|
149
lib/Data/Random/String.pm
Normal file
149
lib/Data/Random/String.pm
Normal file
@ -0,0 +1,149 @@
|
||||
package Data::Random::String;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Exporter;
|
||||
|
||||
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
||||
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = ();
|
||||
@EXPORT_OK = qw(&create_random_string);
|
||||
%EXPORT_TAGS = ( DEFAULT => [qw(&create_random_string)]);
|
||||
|
||||
$VERSION = '0.03';
|
||||
|
||||
|
||||
sub create_random_string
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
my %args = (@_);
|
||||
my $length = $args{length} || '32';
|
||||
my $contains = $args{contains} || 'alphanumeric';
|
||||
|
||||
my $rstring ="";
|
||||
|
||||
for(my $i=0 ; $i< $length ;)
|
||||
{
|
||||
my $j = chr(int(rand(127)));
|
||||
|
||||
if(($j =~ /[0-9]/) and (lc($contains) eq 'numeric'))
|
||||
{
|
||||
$rstring .=$j;
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(($j =~ /[a-zA-Z]/) and (lc($contains) eq 'alpha'))
|
||||
{
|
||||
$rstring .=$j;
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(($j =~ /[a-zA-Z0-9]/) and (lc($contains) eq 'alphanumeric'))
|
||||
{
|
||||
$rstring .=$j;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $rstring;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Data::Random::String - Perl extension for creating random strings
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Data::Random::String;
|
||||
|
||||
# Create a new random string for use in your application
|
||||
my $random_string = Data::Random::String->create_random_string(length=>'32', contains=>'alpha');
|
||||
|
||||
if ($random_string)
|
||||
{
|
||||
print "The random string created is $random_string";
|
||||
} else {
|
||||
print "Unable to create random string";
|
||||
}
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Data::Random::String provides a simple interface for generating random
|
||||
strings that contain numeric, alpha or alphanumeric characters.
|
||||
|
||||
=head1 CREATING A RANDOM STRING
|
||||
|
||||
=head2 C< create_random_string >
|
||||
|
||||
my $random_string = Data::Random::String->create_random_string(length=>'$length', contains=>'$character_group');
|
||||
|
||||
This method returns a new random string that abides by the parameters specified
|
||||
when calling it.
|
||||
|
||||
There are two optional parameters as follows:
|
||||
|
||||
=over
|
||||
|
||||
=item C<< legth >>
|
||||
Used to specify the exact length of the generated string in characters. The default length is 32 characters if no other value is given.
|
||||
|
||||
=item C<< contains >>
|
||||
Identifies the class of characters that can be used to populate this random
|
||||
string.
|
||||
|
||||
The choices are alpha ([a-z,A-Z]), numeric ([0-9]) and alphanumeric ([a-z,A-Z,0-9]).
|
||||
|
||||
=back
|
||||
|
||||
=head1 BUGS AND LIMITATIONS
|
||||
|
||||
No bugs have been reported.
|
||||
|
||||
Please report any bugs or feature requests to
|
||||
C<bug-data-random-string@rt.cpan.org>, or through the web interface at
|
||||
L<http://rt.cpan.org>.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Ioakim (Makis) Marmaridis, E<lt>makis.marmaridis@gmail.comE<gt>
|
||||
|
||||
=head1 COPYRIGHT AND LICENSE
|
||||
|
||||
Copyright (C) 2006 by Ioakim (Makis) Marmaridis, All Rights Reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or modify
|
||||
it under the same terms as Perl itself.
|
||||
|
||||
=cut
|
||||
|
||||
=head1 DISCLAIMER OF WARRANTY
|
||||
|
||||
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
||||
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
|
||||
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
|
||||
NECESSARY SERVICING, REPAIR, OR CORRECTION.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
|
||||
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
|
||||
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
|
||||
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
|
9
t/00-load.t
Normal file
9
t/00-load.t
Normal file
@ -0,0 +1,9 @@
|
||||
#!perl -T
|
||||
|
||||
use Test::More tests => 1;
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Data::Random::String' );
|
||||
}
|
||||
|
||||
diag( "Testing Data::Random::String $Data::Random::String::VERSION, Perl $], $^X" );
|
48
t/boilerplate.t
Normal file
48
t/boilerplate.t
Normal file
@ -0,0 +1,48 @@
|
||||
#!perl -T
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More tests => 3;
|
||||
|
||||
sub not_in_file_ok {
|
||||
my ($filename, %regex) = @_;
|
||||
open my $fh, "<", $filename
|
||||
or die "couldn't open $filename for reading: $!";
|
||||
|
||||
my %violated;
|
||||
|
||||
while (my $line = <$fh>) {
|
||||
while (my ($desc, $regex) = each %regex) {
|
||||
if ($line =~ $regex) {
|
||||
push @{$violated{$desc}||=[]}, $.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (%violated) {
|
||||
fail("$filename contains boilerplate text");
|
||||
diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
|
||||
} else {
|
||||
pass("$filename contains no boilerplate text");
|
||||
}
|
||||
}
|
||||
|
||||
not_in_file_ok(README =>
|
||||
"The README is used..." => qr/The README is used/,
|
||||
"'version information here'" => qr/to provide version information/,
|
||||
);
|
||||
|
||||
not_in_file_ok(Changes =>
|
||||
"placeholder date/time" => qr(Date/time)
|
||||
);
|
||||
|
||||
sub module_boilerplate_ok {
|
||||
my ($module) = @_;
|
||||
not_in_file_ok($module =>
|
||||
'the great new $MODULENAME' => qr/ - The great new /,
|
||||
'boilerplate description' => qr/Quick summary of what the module/,
|
||||
'stub function definition' => qr/function[12]/,
|
||||
);
|
||||
}
|
||||
|
||||
module_boilerplate_ok('lib/Data/Random/String.pm');
|
6
t/pod-coverage.t
Normal file
6
t/pod-coverage.t
Normal file
@ -0,0 +1,6 @@
|
||||
#!perl -T
|
||||
|
||||
use Test::More;
|
||||
eval "use Test::Pod::Coverage 1.04";
|
||||
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
|
||||
all_pod_coverage_ok();
|
Loading…
Reference in New Issue
Block a user