| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Parse::Services; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-11-19'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
67886
|
use 5.010001; |
|
|
1
|
|
|
|
|
11
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
14
|
|
|
|
1
|
|
|
|
|
26
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
37
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
7
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
360
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(parse_services); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %SPEC; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$SPEC{parse_services} = { |
|
16
|
|
|
|
|
|
|
v => 1.1, |
|
17
|
|
|
|
|
|
|
summary => 'Parse /etc/services', |
|
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
|
95
|
my %args = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
my $content = $args{content}; |
|
36
|
1
|
50
|
|
|
|
5
|
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
|
|
|
|
|
2
|
my @res; |
|
44
|
1
|
|
|
|
|
8
|
for my $line (split /^/, $content) { |
|
45
|
11
|
|
|
|
|
28
|
$line =~ s/#.*//; |
|
46
|
11
|
100
|
|
|
|
30
|
next unless $line =~ /\S/; |
|
47
|
6
|
|
|
|
|
10
|
chomp $line; |
|
48
|
6
|
|
|
|
|
25
|
my ($name, $port_proto, @aliases) = split /\s+/, $line; |
|
49
|
6
|
|
|
|
|
18
|
my ($port, $proto) = split m!/!, $port_proto; |
|
50
|
6
|
|
|
|
|
27
|
push @res, { |
|
51
|
|
|
|
|
|
|
name => $name, |
|
52
|
|
|
|
|
|
|
port => $port, |
|
53
|
|
|
|
|
|
|
proto => $proto, |
|
54
|
|
|
|
|
|
|
aliases => \@aliases, |
|
55
|
|
|
|
|
|
|
}; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
1
|
|
|
|
|
21
|
[200, "OK", \@res]; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
# ABSTRACT: Parse /etc/services |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |