line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::RndString; |
2
|
2
|
|
|
2
|
|
13602
|
use 5.008001; |
|
2
|
|
|
|
|
5
|
|
3
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
5
|
2
|
|
|
2
|
|
6
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
882
|
|
6
|
2
|
|
|
2
|
|
7883
|
use Crypt::GeneratePassword qw(chars); |
|
2
|
|
|
|
|
3525
|
|
|
2
|
|
|
|
|
639
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
36941
|
my ($class, $context, $args) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
11
|
my $chrset = [0..9, 'A'..'Z', 'a'..'z']; |
14
|
1
|
50
|
33
|
|
|
6
|
if ($args && (ref $args eq 'HASH')) { |
15
|
0
|
0
|
|
|
|
0
|
if (defined $args->{chrset}) { |
16
|
0
|
0
|
|
|
|
0
|
if (ref $args->{chrset} eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
$chrset = $args->{chrset}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
elsif (!ref $args->{chrset}) { |
20
|
0
|
|
|
|
|
0
|
my @s = split '', $args->{chrset}; |
21
|
0
|
|
|
|
|
0
|
$chrset = \@s; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
bless { |
27
|
1
|
|
|
|
|
5
|
context => $context, |
28
|
|
|
|
|
|
|
chrset => $chrset, |
29
|
|
|
|
|
|
|
}, $class; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub make { |
33
|
1
|
|
|
1
|
0
|
24
|
my ($self, $minlen, $maxlen) = @_; |
34
|
1
|
|
|
|
|
1
|
my $fs = ""; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
33
|
|
|
7
|
if ($minlen && $maxlen) { |
37
|
0
|
0
|
0
|
|
|
0
|
unless (($minlen =~ m/^\d+$/) && ($maxlen =~ m/^\d+$/) && ($minlen <= $maxlen)) { |
|
|
|
0
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
$minlen = $maxlen = 32; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
1
|
|
|
|
|
2
|
$minlen = $maxlen = 32; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
26
|
srand; |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
|
|
2
|
my @letters = grep {m/^[A-Z]$/i} @{$self->{chrset}}; |
|
62
|
|
|
|
|
67
|
|
|
1
|
|
|
|
|
5
|
|
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
3
|
if (@letters) { |
50
|
1
|
|
|
|
|
2
|
--$minlen; --$maxlen; |
|
1
|
|
|
|
|
1
|
|
51
|
1
|
|
|
|
|
5
|
$fs = chars(1,1, \@letters); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
38
|
my $len = int($minlen + (1+$maxlen-$minlen)*rand); |
55
|
1
|
|
|
|
|
4
|
return $fs . chars($len,$len, $self->{chrset}); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |