line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Services; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-10-26'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
13288
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
7
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
8
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use Exporter qw(import); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
253
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_services); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{parse_services} = { |
16
|
|
|
|
|
|
|
v => 1.1, |
17
|
|
|
|
|
|
|
summary => 'Parse /etc/hosts', |
18
|
|
|
|
|
|
|
args => { |
19
|
|
|
|
|
|
|
content => { |
20
|
|
|
|
|
|
|
summary => 'Content of /etc/services file', |
21
|
|
|
|
|
|
|
description => <<'_', |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Optional. Will attempt to read `/etc/services` from filesystem if not specified. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
_ |
26
|
|
|
|
|
|
|
schema => 'str*', |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
examples => [ |
30
|
|
|
|
|
|
|
], |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
sub parse_services { |
33
|
1
|
|
|
1
|
1
|
9
|
my %args = @_; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
3
|
my $content = $args{content}; |
36
|
1
|
50
|
|
|
|
3
|
unless (defined $content) { |
37
|
0
|
0
|
|
|
|
0
|
open my($fh), "<", "/etc/services" |
38
|
|
|
|
|
|
|
or return [500, "Can't read /etc/services: $!"]; |
39
|
0
|
|
|
|
|
0
|
local $/; |
40
|
0
|
|
|
|
|
0
|
$content = <$fh>; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
1
|
my @res; |
44
|
1
|
|
|
|
|
5
|
for my $line (split /^/, $content) { |
45
|
11
|
|
|
|
|
19
|
$line =~ s/#.*//; |
46
|
11
|
100
|
|
|
|
21
|
next unless $line =~ /\S/; |
47
|
6
|
|
|
|
|
4
|
chomp $line; |
48
|
6
|
|
|
|
|
18
|
my ($name, $port_proto, @aliases) = split /\s+/, $line; |
49
|
6
|
|
|
|
|
11
|
my ($port, $proto) = split m!/!, $port_proto; |
50
|
6
|
|
|
|
|
13
|
push @res, { |
51
|
|
|
|
|
|
|
name => $name, |
52
|
|
|
|
|
|
|
port => $port, |
53
|
|
|
|
|
|
|
proto => $proto, |
54
|
|
|
|
|
|
|
aliases => \@aliases, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
|
|
|
|
18
|
[200, "OK", \@res]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
# ABSTRACT: Parse /etc/hosts |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |