line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::RndString; |
2
|
2
|
|
|
2
|
|
13685
|
use 5.008001; |
|
2
|
|
|
|
|
5
|
|
3
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
30
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
41
|
|
5
|
2
|
|
|
2
|
|
4
|
use base 'Template::Plugin'; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
871
|
|
6
|
2
|
|
|
2
|
|
7842
|
use Crypt::GeneratePassword qw(chars); |
|
2
|
|
|
|
|
3597
|
|
|
2
|
|
|
|
|
478
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
1
|
|
|
1
|
1
|
37308
|
my ($class, $context, $args) = @_; |
12
|
1
|
|
|
|
|
12
|
my $chrset = [0..9, 'A'..'Z', 'a'..'z']; |
13
|
1
|
50
|
33
|
|
|
4
|
if ($args && (ref $args eq 'HASH')) { |
14
|
0
|
0
|
0
|
|
|
0
|
if (defined $args->{chrset} && (ref $args->{chrset} eq 'ARRAY')) { |
15
|
0
|
|
|
|
|
0
|
$chrset = $args->{chrset}; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
bless { |
20
|
1
|
|
|
|
|
4
|
context => $context, |
21
|
|
|
|
|
|
|
chrset => $chrset, |
22
|
|
|
|
|
|
|
}, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub make { |
26
|
1
|
|
|
1
|
0
|
24
|
my ($self, $minlen, $maxlen) = @_; |
27
|
1
|
50
|
33
|
|
|
7
|
if ($minlen && $maxlen) { |
28
|
0
|
0
|
0
|
|
|
0
|
unless (($minlen =~ m/^\d+$/) && ($maxlen =~ m/^\d+$/) && ($minlen <= $maxlen)) { |
|
|
|
0
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
$minlen = $maxlen = 32; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
1
|
|
|
|
|
2
|
$minlen = $maxlen = 32; |
34
|
|
|
|
|
|
|
} |
35
|
1
|
|
|
|
|
26
|
srand; |
36
|
1
|
|
|
|
|
6
|
my $len = int($minlen + (1+$maxlen-$minlen)*rand); |
37
|
1
|
|
|
|
|
54
|
my @set = eval $self->{chrset}; |
38
|
1
|
|
|
|
|
7
|
return chars($len,$len, $self->{chrset}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |