line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scalar::Random::PP; |
2
|
2
|
|
|
2
|
|
70637
|
use Scalar::Random::PP::OO; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
64
|
use 5.008003; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
260
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'limit' => ( is => 'ro' ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Scalar::Random::PP::OO::Exporter->setup_import_methods( |
10
|
|
|
|
|
|
|
as_is => [\&randomize], |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use overload |
14
|
271
|
|
|
271
|
|
26183
|
'""' => sub { int(rand($_[0]->limit + 1)) }, |
15
|
2
|
|
|
2
|
|
12
|
fallback => 1; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub randomize { |
18
|
4
|
|
|
4
|
0
|
715
|
$_[0] = Scalar::Random::PP->new(limit => $_[1]); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=encoding utf8 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Scalar::Random::PP - Scalar::Random in Pure Perl |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Scalar::Random::PP 'randomize'; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $random; |
34
|
|
|
|
|
|
|
my $MAX_RANDOM = 100; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
randomize( $random, $MAX_RANDOM ); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
print $random, "\n"; # '42' |
39
|
|
|
|
|
|
|
print $random, "\n"; # '17' |
40
|
|
|
|
|
|
|
print $random, "\n"; # '88' |
41
|
|
|
|
|
|
|
print $random, "\n"; # '4' |
42
|
|
|
|
|
|
|
print $random, "\n"; # '50' |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module is intended to be a pure Perl replacement for L. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Please see L for full details. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NOTES |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This module was written as a pair programming excerise between |
53
|
|
|
|
|
|
|
Webster Montego and Ingy döt Net. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The module passes all the same tests as L, even though |
56
|
|
|
|
|
|
|
we felt there could be more exhaustive testing. Perhaps we'll add the |
57
|
|
|
|
|
|
|
tests we'd like to see, so that Alfie John can backport them. :) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
We also thought it would be nice if randomize took a lower limit, but we |
60
|
|
|
|
|
|
|
decided not to change the API unless Alfie did so first, so that the PP |
61
|
|
|
|
|
|
|
module would be an exact replacement. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
We used the speedy and zero-dep L module for OO goodness, and |
64
|
|
|
|
|
|
|
packaged it all up with the lovely L and friends. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 RESOURCES |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
GitHub: L |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHORS |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Webster Montego |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Ingy döt Net |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 COPYRIGHT |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Copyright (c) 2010. Webster Montego and Ingy döt Net |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
81
|
|
|
|
|
|
|
under the same terms as Perl itself. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
See L |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |