line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mock::Data::Plugin::Net; |
2
|
2
|
|
|
2
|
|
1035
|
use Mock::Data::Plugin -exporter_setup => 1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
3
|
|
|
|
|
|
|
our @generators= qw( ipv4 cidr macaddr ); |
4
|
|
|
|
|
|
|
export(@generators); |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: Collection of generators for Internet-related data |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub apply_mockdata_plugin { |
11
|
1
|
|
|
1
|
0
|
4
|
my ($class, $mock)= @_; |
12
|
1
|
|
|
|
|
15
|
$mock->add_generators( |
13
|
|
|
|
|
|
|
map +("Net::$_" => $class->can($_)), @generators |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub ipv4 { |
19
|
10
|
|
|
10
|
1
|
73
|
sprintf "127.%d.%d.%d", rand 256, rand 256, 1+rand 254; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub cidr { |
24
|
10
|
|
|
10
|
1
|
32
|
my $blank= 1 + int rand 23; |
25
|
10
|
|
|
|
|
26
|
my $val= (int rand(1<<(24 - $blank))) << $blank; |
26
|
10
|
|
|
|
|
92
|
sprintf '127.%d.%d.%d/%d', (unpack 'C4', pack 'N', $val)[1,2,3], 32 - $blank; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub macaddr { |
31
|
10
|
|
|
10
|
1
|
84
|
sprintf '%02x:%02x:%02x:%02x:%02x:%02x', |
32
|
|
|
|
|
|
|
((rand 64)<<2) | 0x02, rand 256, rand 256, |
33
|
|
|
|
|
|
|
rand 256, rand 256, rand 256 |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |