blib/lib/hostname.pl | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 11 | 81.8 |
branch | 1 | 4 | 25.0 |
condition | 2 | 12 | 16.6 |
subroutine | 2 | 2 | 100.0 |
pod | n/a | ||
total | 14 | 29 | 48.2 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | # From: asherman@fmrco.com (Aaron Sherman) | ||||||
2 | # | ||||||
3 | # This library is no longer being maintained, and is included for backward | ||||||
4 | # compatibility with Perl 4 programs which may require it. | ||||||
5 | # | ||||||
6 | # In particular, this should not be used as an example of modern Perl | ||||||
7 | # programming techniques. | ||||||
8 | # | ||||||
9 | # Suggested alternative: Sys::Hostname | ||||||
10 | # | ||||||
11 | 2 | 2 | 1529 | no warnings "ambiguous"; | |||
2 | 4 | ||||||
2 | 328 | ||||||
12 | |||||||
13 | sub hostname | ||||||
14 | { | ||||||
15 | 1 | 1 | 700 | local(*P,@tmp,$hostname,$_); | |||
16 | 1 | 50 | 33 | 2514 | if (open(P,"hostname 2>&1 |") && (@tmp = ) && close(P)) |
||
0 | 33 | ||||||
0 | |||||||
0 | |||||||
17 | { | ||||||
18 | 1 | 18 | chop($hostname = $tmp[$#tmp]); | ||||
19 | } | ||||||
20 | elsif (open(P,"uname -n 2>&1 |") && (@tmp = ) && close(P)) |
||||||
21 | { | ||||||
22 | 0 | 0 | chop($hostname = $tmp[$#tmp]); | ||||
23 | } | ||||||
24 | else | ||||||
25 | { | ||||||
26 | 0 | 0 | die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n"; | ||||
27 | } | ||||||
28 | 1 | 7 | @tmp = (); | ||||
29 | 1 | 5 | close P; # Just in case we failed in an odd spot.... | ||||
30 | 1 | 31 | $hostname; | ||||
31 | } | ||||||
32 | |||||||
33 | 1; |