From 6377f67204f28c9dc2c9ed7e999d3019572c4fc6 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Tue, 27 Mar 2018 20:51:49 +0200 Subject: [PATCH] Imported Upstream version 0.03 --- Changes | 11 +++ MANIFEST | 10 +++ META.yml | 19 +++++ Makefile.PL | 16 ++++ README | 32 ++++++++ lib/Data/Random/String.pm | 149 ++++++++++++++++++++++++++++++++++++++ t/00-load.t | 9 +++ t/boilerplate.t | 48 ++++++++++++ t/pod-coverage.t | 6 ++ t/pod.t | 6 ++ 10 files changed, 306 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 META.yml create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/Data/Random/String.pm create mode 100644 t/00-load.t create mode 100644 t/boilerplate.t create mode 100644 t/pod-coverage.t create mode 100644 t/pod.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..93537c4 --- /dev/null +++ b/Changes @@ -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. + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..4d96a7a --- /dev/null +++ b/MANIFEST @@ -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 diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..7411047 --- /dev/null +++ b/META.yml @@ -0,0 +1,19 @@ +--- +name: Data-Random-String +version: 0.03 +author: + - 'Ioakim (Makis) Marmaridis ' +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 diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..c7f439f --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,16 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Data::Random::String', + AUTHOR => 'Ioakim (Makis) Marmaridis ', + 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-*' }, +); diff --git a/README b/README new file mode 100644 index 0000000..ba44c6c --- /dev/null +++ b/README @@ -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. + diff --git a/lib/Data/Random/String.pm b/lib/Data/Random/String.pm new file mode 100644 index 0000000..fb1c970 --- /dev/null +++ b/lib/Data/Random/String.pm @@ -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, or through the web interface at +L. + +=head1 AUTHOR + +Ioakim (Makis) Marmaridis, Emakis.marmaridis@gmail.comE + +=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. + + diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..9d35df0 --- /dev/null +++ b/t/00-load.t @@ -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" ); diff --git a/t/boilerplate.t b/t/boilerplate.t new file mode 100644 index 0000000..7affa79 --- /dev/null +++ b/t/boilerplate.t @@ -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'); diff --git a/t/pod-coverage.t b/t/pod-coverage.t new file mode 100644 index 0000000..703f91d --- /dev/null +++ b/t/pod-coverage.t @@ -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(); diff --git a/t/pod.t b/t/pod.t new file mode 100644 index 0000000..976d7cd --- /dev/null +++ b/t/pod.t @@ -0,0 +1,6 @@ +#!perl -T + +use Test::More; +eval "use Test::Pod 1.14"; +plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; +all_pod_files_ok();