lib/Rex/Group/Lookup/File.pm

filter: Statementstmt 68.1% 15 / 22 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 66.6% 20 / 30 CC 2 SCAR 9.8
CC
2
Cov
62%
lookup_file
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« lib/Rex/Inventory/SMBios/SystemInformation.pm ↑ Summary lib/Rex/Inventory/DMIDecode/Memory.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
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 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 our $VERSION = '1.16.1'; # VERSION
29  
30 1 require Exporter;
31 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 1 @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 0 ▶sub lookup_file {
Subroutine lookup_file: not called CC=2 SCAR=17.9
Pod documented
46 0 my ($file) = @_;
47  
48 0 ▶ open( my $fh, "<", $file ) or die($!);
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die $! 0 0 0
49 0 my @content = grep { !/^\s*$|^#/ } <$fh>;
50 0 close($fh);
51  
52 0 chomp @content;
53  
54 0 return @content;
55 }
56  
57 1 1;
« lib/Rex/Inventory/SMBios/SystemInformation.pm ↑ Summary lib/Rex/Inventory/DMIDecode/Memory.pm »