File Coverage

blib/lib/Net/DNS/Resolver/UNIX.pm
Criterion Covered Total %
statement 20 21 100.0
branch 2 2 100.0
path n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 26 27 100.0


line stmt bran path cond sub pod time code
1               package Net::DNS::Resolver::UNIX;
2                
3 94       94   651 use strict;
  94           131  
  94           2766  
4 94       94   355 use warnings;
  94           150  
  94           37590  
5               our $VERSION = (qw$Id: UNIX.pm 2046 2026-06-01 13:23:01Z willem $)[2];
6                
7                
8               =head1 NAME
9                
10               Net::DNS::Resolver::UNIX - Unix resolver class
11                
12               =cut
13                
14                
15               my @config_file = grep { -f $_ && -r $_ } '/etc/resolv.conf';
16                
17               my $homedir = $ENV{HOME};
18               my $dotfile = '.resolv.conf';
19               my @dotfile = grep { -f $_ && -o $_ } map {"$_/$dotfile"} grep {$_} $homedir, '.';
20                
21               my ($name) = _nosh(qw(uname -n));
22               chomp $name;
23               my ( undef, @domain ) = split /\./, $name, 2;
24                
25                
26               sub _init {
27 8       8   25 my $defaults = shift->_defaults;
28                
29 8           44 $defaults->domain(@domain);
30 8           38 $defaults->_read_config_file($_) foreach @config_file;
31                
32 8           72 %$defaults = Net::DNS::Resolver::Base::_untaint(%$defaults);
33                
34 8           62 $defaults->_read_config_file($_) foreach @dotfile;
35                
36 8           36 $defaults->_read_env;
37 8           14 return;
38               }
39                
40               sub _nosh { ## shell-free backtick emulation
41 94       94   238 my ( $prog, @arg ) = @_;
42 94 100         142988 if ( open( PIPE, '-|' ) ) {
43 92           24039761 my @retval = ;
44 92           10382 close PIPE;
45 92           2108 return @retval;
46               } else {
47 2           384 $ENV{PATH} = '/bin:/usr/bin';
48 2             exec $prog, @arg;
49 0             exit; ## uncoverable statement
50               }
51               }
52                
53               1;
54               __END__