File Coverage

lib/Rex/Group/Lookup/File.pm
Criterion Covered Total %
statement 11 18 61.1
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 16 26 61.5


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             =head1 NAME
6              
7             Rex::Group::Lookup::File - read hostnames from a file.
8              
9             =head1 DESCRIPTION
10              
11             With this module you can define hostgroups out of a file.
12              
13             =head1 SYNOPSIS
14              
15             use Rex::Group::Lookup::File;
16             group "webserver" => lookup_file("./hosts.lst");
17              
18              
19             =head1 EXPORTED FUNCTIONS
20              
21             =cut
22              
23             package Rex::Group::Lookup::File;
24              
25 1     1   15 use v5.12.5;
  1         4  
26 1     1   5 use warnings;
  1         3  
  1         50  
27              
28             our $VERSION = '1.14.2.2'; # TRIAL VERSION
29              
30             require Exporter;
31 1     1   7 use base qw(Exporter);
  1         2  
  1         78  
32 1     1   15 use vars qw(@EXPORT);
  1         2  
  1         188  
33              
34             @EXPORT = qw(lookup_file);
35              
36             =head2 lookup_file($file)
37              
38             With this function you can read hostnames from a file. Every hostname in one line.
39              
40             group "webserver" => lookup_file("./webserver.lst");
41             group "mailserver" => lookup_file("./mailserver.lst");
42              
43             =cut
44              
45             sub lookup_file {
46 0     0 1   my ($file) = @_;
47              
48 0 0         open( my $fh, "<", $file ) or die($!);
49 0           my @content = grep { !/^\s*$|^#/ } <$fh>;
  0            
50 0           close($fh);
51              
52 0           chomp @content;
53              
54 0           return @content;
55             }
56              
57             1;