| 1 | package Configd; | ||||||||||||||||||||||||||||
| 2 | 1 | $Configd::VERSION = '0.007'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: Give software without a conf.d one anyway. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use 5.034; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use re '/aa'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use File::Basename qw{basename}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Module::Load (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Configd::Unit(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub languages { | ||||||||||||||||||||||||||
|
Subroutine
languages: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my %seen; | |||||||||||||||||||||||||||
| 20 | 0 | foreach my $dir (@INC) { | |||||||||||||||||||||||||||
| 21 | 0 | my $path = "$dir/Configd/Language"; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | opendir( my $dh, $path ) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | foreach my $file ( readdir($dh) ) { | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | next unless $file =~ m/\A(\w+)[.]pm\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | $seen{$1} = 1; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | closedir $dh; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | return sort keys %seen; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub language { | ||||||||||||||||||||||||||
|
Subroutine
language: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | die "Which language?\n" unless defined $name && length $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and length $name
MC/DC0%0/2
defined $name and length $name
defined $name
length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # It becomes part of a module name, so it has to be a name and not a path. | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | die "'$name' is not a language name\n" unless $name =~ m/\A\w+\z/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $module = "Configd::Language::$name"; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | eval { Module::Load::load($module); 1 } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | my $error = $@; | |||||||||||||||||||||||||||
| 45 | 0 | my @known = $class->languages(); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # A language that is here and does not load is not a typo. The ossec | ||||||||||||||||||||||||||||
| 48 | # language needs XML::LibXML, and "no language" would send whoever | ||||||||||||||||||||||||||||
| 49 | # reads it looking for the wrong thing. | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | die "The language '$name' does not load: $error" if grep { $_ eq $name } @known; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | die "No language '$name'. This installation knows: " . join( ', ', @known ) . "\n"; | |||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | return $module->new(%opts); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub build { | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $language = $class->language( $name, %opts ); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | my @changed; | |||||||||||||||||||||||||||
| 64 | 0 | foreach my $file ( $language->files() ) { | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | push @changed, $file->{path} if $language->write($file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return @changed; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub adopt { | ||||||||||||||||||||||||||
|
Subroutine
adopt: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $language = $class->language( $name, %opts ); | |||||||||||||||||||||||||||
| 76 | 0 | my @adopted = $language->adopt(); | |||||||||||||||||||||||||||
| 77 | 0 | my $unit = Configd::Unit->new( language => $language, %opts ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | return { | ||||||||||||||||||||||||||||
| 80 | 0 | adopted => \@adopted, | |||||||||||||||||||||||||||
| 81 | dropins => [ $unit->install() ], | ||||||||||||||||||||||||||||
| 82 | services => [ $language->services() ], | ||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub release { | ||||||||||||||||||||||||||
|
Subroutine
release: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my $language = $class->language( $name, %opts ); | |||||||||||||||||||||||||||
| 91 | 0 | my $unit = Configd::Unit->new( language => $language, %opts ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | return { | ||||||||||||||||||||||||||||
| 94 | 0 | dropins => [ $unit->uninstall() ], | |||||||||||||||||||||||||||
| 95 | released => [ $language->release() ], | ||||||||||||||||||||||||||||
| 96 | services => [ $language->services() ], | ||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub status { | ||||||||||||||||||||||||||
|
Subroutine
status: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $language = $class->language( $name, %opts ); | |||||||||||||||||||||||||||
| 105 | 0 | my $unit = Configd::Unit->new( language => $language, %opts ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my @files; | |||||||||||||||||||||||||||
| 108 | 0 | foreach my $file ( $language->files() ) { | |||||||||||||||||||||||||||
| 109 | 0 | my @fragments = $language->fragments($file); | |||||||||||||||||||||||||||
| 110 | push @files, { | ||||||||||||||||||||||||||||
| 111 | path => $file->{path}, | ||||||||||||||||||||||||||||
| 112 | 0 | adopted => ( scalar grep { basename($_) eq '00-original' } @fragments ) ? 1 : 0, | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | fragments => [ map { basename($_) } @fragments ], | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | return { | ||||||||||||||||||||||||||||
| 118 | 0 | language => $language->name(), | |||||||||||||||||||||||||||
| 119 | files => \@files, | ||||||||||||||||||||||||||||
| 120 | units => [ $language->units() ], | ||||||||||||||||||||||||||||
| 121 | wrapped => $unit->installed(), | ||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | 1; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | __END__ | ||||||||||||||||||||||||||||