Configd.pm

filter: Statementstmt 33.3% 22 / 66 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 100% 6 / 6 totaltotal 33.6% 35 / 104 CC 13 SCAR 27.3
CC
13
Cov
27%
languages
30.0
language
30.0
build
12.0
CRAP 15.3
« Configd/Syntax/Spaced.pm ↑ Summary Configd/Language/redis.pm »
1 package Configd;
2 1 $Configd::VERSION = '0.005';
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
BranchTrueFalseTotal
opendir my $dh, $path or next 0 0 0
23 0 foreach my $file ( readdir($dh) ) {
24 0 ▶ next unless $file =~ m/\A(\w+)[.]pm\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\A(\w+)[.]pm\z/aa 0 0 0
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=5 SCAR=34.0
Pod documented
35 0 my ( $class, $name, %opts ) = @_;
36  
37 0 ▶ die "Which language?\n" unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $name =~ /\A\w+\z/aa 0 0 0
41  
42 0 my $module = "Configd::Language::$name";
43 0 ▶ eval { Module::Load::load($module); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &Module::Load::load($module); 1 } } or do { my(@known) = $class->languages; die "No language '${name}'. This installation knows: " . join(", ", @known) . "\n" } 0 0 0
44 0 my @known = $class->languages();
45 0 die "No language '$name'. This installation knows: " . join( ', ', @known ) . "\n";
46 };
47  
48 0 return $module->new(%opts);
49 }
50  
51  
52 0 ▶sub build {
Subroutine build: not called CC=3 SCAR=24.8
Pod documented
53 0 my ( $class, $name, %opts ) = @_;
54  
55 0 my $language = $class->language( $name, %opts );
56  
57 0 my @changed;
58 0 foreach my $file ( $language->files() ) {
59 0 ▶ push @changed, $file->{path} if $language->write($file);
Branch: 1 branch
BranchTrueFalseTotal
if $language->write($file) 0 0 0
60 }
61  
62 0 return @changed;
63 }
64  
65  
66 0 ▶sub adopt {
Subroutine adopt: not called CC=1 SCAR=6.9
Pod documented
67 0 my ( $class, $name, %opts ) = @_;
68  
69 0 my $language = $class->language( $name, %opts );
70 0 my @adopted = $language->adopt();
71 0 my $unit = Configd::Unit->new( language => $language, %opts );
72  
73 return {
74 0 adopted => \@adopted,
75 dropins => [ $unit->install() ],
76 services => [ $language->services() ],
77 };
78 }
79  
80  
81 0 ▶sub release {
Subroutine release: not called CC=1 SCAR=6.9
Pod documented
82 0 my ( $class, $name, %opts ) = @_;
83  
84 0 my $language = $class->language( $name, %opts );
85 0 my $unit = Configd::Unit->new( language => $language, %opts );
86  
87 return {
88 0 dropins => [ $unit->uninstall() ],
89 released => [ $language->release() ],
90 services => [ $language->services() ],
91 };
92 }
93  
94  
95 0 ▶sub status {
Subroutine status: not called CC=3 SCAR=24.8
Pod documented
96 0 my ( $class, $name, %opts ) = @_;
97  
98 0 my $language = $class->language( $name, %opts );
99 0 my $unit = Configd::Unit->new( language => $language, %opts );
100  
101 0 my @files;
102 0 foreach my $file ( $language->files() ) {
103 0 my @fragments = $language->fragments($file);
104 push @files, {
105 path => $file->{path},
106 0 adopted => ( scalar grep { basename($_) eq '00-original' } @fragments ) ? 1 : 0,
107 0 ▶ fragments => [ map { basename($_) } @fragments ],
Branch: 1 branch
BranchTrueFalseTotal
scalar grep({basename($_) eq '00-original';} @fragments) ? : 0 0 0
108 };
109 }
110  
111 return {
112 0 language => $language->name(),
113 files => \@files,
114 units => [ $language->units() ],
115 wrapped => $unit->installed(),
116 };
117 }
118  
119  
120 1 1;
121  
122 __END__
« Configd/Syntax/Spaced.pm ↑ Summary Configd/Language/redis.pm »