File Coverage

blib/lib/Data/Random/String.pm
Criterion Covered Total %
statement 12 29 41.3
branch 0 6 0.0
condition 0 13 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 54 31.4


line stmt bran cond sub pod time code
1             package Data::Random::String;
2              
3 1     1   23748 use strict;
  1         3  
  1         35  
4 1     1   5 use warnings;
  1         2  
  1         27  
5 1     1   4 use Exporter;
  1         6  
  1         52  
6              
7 1     1   5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  1         2  
  1         335  
8              
9             @ISA = qw(Exporter);
10             @EXPORT = ();
11             @EXPORT_OK = qw(&create_random_string);
12             %EXPORT_TAGS = ( DEFAULT => [qw(&create_random_string)]);
13              
14             $VERSION = '0.03';
15              
16              
17             sub create_random_string
18             {
19 0     0 1   my $self = shift;
20              
21 0           my %args = (@_);
22 0   0       my $length = $args{length} || '32';
23 0   0       my $contains = $args{contains} || 'alphanumeric';
24              
25 0           my $rstring ="";
26            
27 0           for(my $i=0 ; $i< $length ;)
28             {
29 0           my $j = chr(int(rand(127)));
30            
31 0 0 0       if(($j =~ /[0-9]/) and (lc($contains) eq 'numeric'))
32             {
33 0           $rstring .=$j;
34 0           $i++;
35             }
36              
37 0 0 0       if(($j =~ /[a-zA-Z]/) and (lc($contains) eq 'alpha'))
38             {
39 0           $rstring .=$j;
40 0           $i++;
41             }
42              
43 0 0 0       if(($j =~ /[a-zA-Z0-9]/) and (lc($contains) eq 'alphanumeric'))
44             {
45 0           $rstring .=$j;
46 0           $i++;
47             }
48             }
49 0           return $rstring;
50             }
51              
52             1;
53              
54              
55             __END__