scripts/llng-build-manager-files

filter: Statementstmt 46.4% 255 / 549 Branchbran 25.0% 63 / 252 Conditioncond 28.1% 45 / 160 MC/DCmcdc 5.6% 5 / 89 Subroutinesub 68.4% 26 / 38 Podpod n/a totaltotal 36.2% 394 / 1088 CC 152 SCAR 38.7
CC
152
Cov
38%
update_language_files
156.0
minify_conftree
156.0
collect_auth_plugins
107.3
CRAP 47.9
« blib/lib/Lemonldap/NG/Manager/Cli.pm ↑ Summary blib/lib/Lemonldap/NG/Manager/Conf/Diff.pm »
1 #!/usr/bin/perl
2 #
3 # llng-build-manager-files - Regenerate LemonLDAP::NG Manager with plugin extensions
4 #
5 # This script allows plugins to extend the Manager configuration by adding
6 # new attributes, tree nodes, and portal constants. Extensions can be in
7 # Perl (.pm) or JSON (.json) format.
8 #
9 # Usage:
10 # llng-build-manager-files --plugins-dir=/etc/lemonldap-ng/manager-overrides.d --plugins-dir=/other/dir
11 #
12 # Paths are configured via placeholders replaced during installation.
13 # All paths can be overridden via command line options.
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Basename qw(dirname basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # Pod::Usage is optional - provide fallback if not available
24 1 my $has_pod_usage = eval { require Pod::Usage; 1 };
25  
26 0 ▶sub show_help {
Subroutine show_help: not called CC=2 SCAR=17.9
27 0 my ( $exitcode, $verbose ) = @_;
28 0 ▶ if ($has_pod_usage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_pod_usage) { } 0 0 0
29 0 Pod::Usage::pod2usage( -exitcode => $exitcode, -verbose => $verbose );
30 }
31 else {
32 0 print
33 "Usage: llng-build-manager-files [--plugins-dir=<path> ...] [options]\n";
34 0 print "Use 'perldoc $0' for full documentation.\n";
35 0 exit $exitcode;
36 }
37 }
38  
39 # Load the core Build modules to get their data
40 1 require Lemonldap::NG::Manager::Build::Attributes;
41 1 require Lemonldap::NG::Manager::Build::Tree;
42 1 require Lemonldap::NG::Manager::Build::CTrees;
43 1 require Lemonldap::NG::Manager::Build::PortalConstants;
44  
45 1 my $VERSION = '2.23.0';
46  
47 #############################################################################
48 # Default paths - placeholders replaced during installation
49 # These can all be overridden via command line options
50 #############################################################################
51 1 my $DEFAULT_MANAGERSTATICDIR = '__MANAGERSTATICDIR__';
52 1 my $DEFAULT_PERLLIBDIR = '__INSTALLSITELIB__';
53 1 my $DEFAULT_DOCDIR = '__DOCDIR__';
54 1 my $DEFAULT_LANGDIR = '__MANAGERSTATICDIR__/languages';
55  
56 # Command line options
57 1 my @plugins_dirs;
58 my (
59 1 $struct_file, $conftree_file,
60 $manager_constants_file, $manager_attributes_file,
61 $default_values_file, $conf_constants_file,
62 $first_lmconf_file, $reverse_tree_file,
63 $portal_constants_file, $handler_status_constants_file,
64 $doc_constants_file, $lang_dir,
65 $help, $verbose,
66 );
67  
68 1 ▶GetOptions(
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("plugins-dir=s", \@plugins_dirs, "struct-file=s", \$struct_file, "conftree-file=s", \$conftree_file, "manager-constants-file=s", \$manager_constants_file, "manager-attributes-file=s", \$manager_attributes_file, "default-values-file=s", \$default_values_file, "conf-constants-file=s", \$conf_constants_file, "first-lmconf-file=s", \$first_lmconf_file, "reverse-tree-file=s", \$reverse_tree_file, "portal-constants-file=s", \$portal_constants_file, "handler-status-constants-file=s", \$handler_status_constants_file, "doc-constants-file=s", \$doc_constants_file, "lang-dir=s", \$lang_dir, "help|h", \$help, "verbose|v", \$verbose) or show_help(1, 0) 1 0 1
69 'plugins-dir=s' => \@plugins_dirs,
70 'struct-file=s' => \$struct_file,
71 'conftree-file=s' => \$conftree_file,
72 'manager-constants-file=s' => \$manager_constants_file,
73 'manager-attributes-file=s' => \$manager_attributes_file,
74 'default-values-file=s' => \$default_values_file,
75 'conf-constants-file=s' => \$conf_constants_file,
76 'first-lmconf-file=s' => \$first_lmconf_file,
77 'reverse-tree-file=s' => \$reverse_tree_file,
78 'portal-constants-file=s' => \$portal_constants_file,
79 'handler-status-constants-file=s' => \$handler_status_constants_file,
80 'doc-constants-file=s' => \$doc_constants_file,
81 'lang-dir=s' => \$lang_dir,
82 'help|h' => \$help,
83 'verbose|v' => \$verbose,
84 ) or show_help( 1, 0 );
85  
86 1 ▶show_help( 0, 2 ) if $help;
Branch: 1 branch
BranchTrueFalseTotal
if $help 0 1 1
87  
88 13 ▶sub verbose {
Subroutine verbose: called CC=2 SCAR=7.6
89 13 ▶ print @_ if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 13 13
90 }
91  
92 # plugins-dir is optional - if not specified or doesn't exist, run without extensions
93 @plugins_dirs = grep {
94 1 ▶ if ( !-d $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -d $_) { } 0 1 1
95 0 print STDERR
96 "Note: Plugins directory not found: $_ (continuing without extensions)\n";
97 0 0;
98 }
99 1 else { 1 }
100 } @plugins_dirs;
101  
102 # Set default paths from placeholders (can be overridden via options)
103 1 ▶$struct_file //= "$DEFAULT_MANAGERSTATICDIR/struct.json";
Condition50%1/2
$struct_file //= "$DEFAULT_MANAGERSTATICDIR/struct.json"
l!l
10
MC/DC0%0/1
$struct_file //= "$DEFAULT_MANAGERSTATICDIR/struct.json"
$struct_file
Truth table50%1/2
A
A= $struct_file
Aresult
11
00
104 1 ▶$conftree_file //= "$DEFAULT_MANAGERSTATICDIR/js/conftree.js";
Condition50%1/2
$conftree_file //= "$DEFAULT_MANAGERSTATICDIR/js/conftree.js"
l!l
10
MC/DC0%0/1
$conftree_file //= "$DEFAULT_MANAGERSTATICDIR/js/conftree.js"
$conftree_file
Truth table50%1/2
A
A= $conftree_file
Aresult
11
00
105 1 ▶$reverse_tree_file //= "$DEFAULT_MANAGERSTATICDIR/reverseTree.json";
Condition50%1/2
$reverse_tree_file //= "$DEFAULT_MANAGERSTATICDIR/reverseTree.json"
l!l
10
MC/DC0%0/1
$reverse_tree_file //= "$DEFAULT_MANAGERSTATICDIR/reverseTree.json"
$reverse_tree_file
Truth table50%1/2
A
A= $reverse_tree_file
Aresult
11
00
106 1 ▶$manager_constants_file //=
Condition50%1/2
$manager_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/ReConstants.pm"
l!l
10
MC/DC0%0/1
$manager_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/ReConstants.pm"
$manager_constants_file
Truth table50%1/2
A
A= $manager_constants_file
Aresult
11
00
107 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/ReConstants.pm";
108 1 ▶$manager_attributes_file //=
Condition50%1/2
$manager_attributes_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Manager/Attributes.pm"
l!l
10
MC/DC0%0/1
$manager_attributes_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Manager/Attributes.pm"
$manager_attributes_file
Truth table50%1/2
A
A= $manager_attributes_file
Aresult
11
00
109 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Manager/Attributes.pm";
110 1 ▶$default_values_file //=
Condition50%1/2
$default_values_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/DefaultValues.pm"
l!l
10
MC/DC0%0/1
$default_values_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/DefaultValues.pm"
$default_values_file
Truth table50%1/2
A
A= $default_values_file
Aresult
11
00
111 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/DefaultValues.pm";
112 1 ▶$conf_constants_file //=
Condition50%1/2
$conf_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/Constants.pm"
l!l
10
MC/DC0%0/1
$conf_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/Constants.pm"
$conf_constants_file
Truth table50%1/2
A
A= $conf_constants_file
Aresult
11
00
113 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Common/Conf/Constants.pm";
114 1 ▶$portal_constants_file //=
Condition50%1/2
$portal_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Portal/Main/Constants.pm"
l!l
10
MC/DC0%0/1
$portal_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Portal/Main/Constants.pm"
$portal_constants_file
Truth table50%1/2
A
A= $portal_constants_file
Aresult
11
00
115 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Portal/Main/Constants.pm";
116 1 ▶$handler_status_constants_file //=
Condition50%1/2
$handler_status_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Handler/Lib/StatusConstants.pm"
l!l
10
MC/DC0%0/1
$handler_status_constants_file //= "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Handler/Lib/StatusConstants.pm"
$handler_status_constants_file
Truth table50%1/2
A
A= $handler_status_constants_file
Aresult
11
00
117 "$DEFAULT_PERLLIBDIR/Lemonldap/NG/Handler/Lib/StatusConstants.pm";
118 1 ▶$first_lmconf_file //= '/dev/null';
Condition50%1/2
$first_lmconf_file //= "/dev/null"
l!l
01
MC/DC0%0/1
$first_lmconf_file //= "/dev/null"
$first_lmconf_file
Truth table50%1/2
A
A= $first_lmconf_file
Aresult
11
00
119 1 ▶$doc_constants_file //= '/dev/null';
Condition50%1/2
$doc_constants_file //= "/dev/null"
l!l
01
MC/DC0%0/1
$doc_constants_file //= "/dev/null"
$doc_constants_file
Truth table50%1/2
A
A= $doc_constants_file
Aresult
11
00
120 1 ▶$lang_dir //= $DEFAULT_LANGDIR;
Condition33%1/3
$lang_dir //= $DEFAULT_LANGDIR
l!l&&r!l&&!r
100
MC/DC0%0/2
$lang_dir //= $DEFAULT_LANGDIR
$lang_dir $DEFAULT_LANGDIR
Truth table33%1/3
A //= B
A= $lang_dirB= $DEFAULT_LANGDIR
ABresult
1X1
011
000
121  
122 # Validate that placeholders were replaced (unless overridden)
123 1 ▶if ( $struct_file =~ /__(?:MANAGERSTATICDIR|INSTALLSITELIB)__/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($struct_file =~ /__(?:MANAGERSTATICDIR|INSTALLSITELIB)__/) 0 1 1
124 0 die "Error: placeholders not replaced during installation.\n"
125 . "Please specify paths via command line options.\n";
126 }
127  
128 1 ▶verbose "Configuration:\n"
Branch: 1 branch
BranchTrueFalseTotal
@plugins_dirs ? : 1 0 1
129 . " plugins-dir: "
130 . ( @plugins_dirs ? join( ', ', @plugins_dirs ) : '(none)' ) . "\n"
131 . " struct-file: $struct_file\n"
132 . " conftree-file: $conftree_file\n"
133 . " manager-constants-file: $manager_constants_file\n"
134 . " manager-attributes-file: $manager_attributes_file\n"
135 . " default-values-file: $default_values_file\n"
136 . " conf-constants-file: $conf_constants_file\n"
137 . " reverse-tree-file: $reverse_tree_file\n"
138 . " portal-constants-file: $portal_constants_file\n"
139 . " handler-status-constants-file: $handler_status_constants_file\n"
140 . " lang-dir: $lang_dir\n" . "\n";
141  
142 # 1. Load core data from Build modules
143 1 verbose "Loading core configuration data...\n";
144 1 my $attributes = Lemonldap::NG::Manager::Build::Attributes::attributes();
145 1 my $tree = Lemonldap::NG::Manager::Build::Tree::tree();
146 1 my $ctrees = Lemonldap::NG::Manager::Build::CTrees::cTrees();
147 1 my $constants =
148 Lemonldap::NG::Manager::Build::PortalConstants::portalConstants();
149  
150 # 2. Load and merge extensions from plugins directory
151 1 my @ext_files;
152 1 ▶if (@plugins_dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@plugins_dirs) { } 1 0 1
153 1 for my $dir (@plugins_dirs) {
154 1 ▶ my @files = sort( glob("$dir/*.pm"), glob("$dir/*.json") );
Subroutine BEGIN: called CC=1 SCAR=0.0
155 1 ▶ verbose @files
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 1 0 1
156 ? "Found " . scalar(@files) . " extension file(s) in $dir\n"
157 : "No extension files found in $dir\n";
158 1 push @ext_files, @files;
159 }
160 }
161 else {
162 0 verbose "No plugins directory specified, running without extensions\n";
163 }
164  
165 1 my @auth_plugins;
166 1 for my $ext_file (@ext_files) {
167 1 verbose "Loading extension: $ext_file\n";
168 1 my $ext = load_extension($ext_file);
169 1 merge_extension( $attributes, $tree, $ctrees, $constants, $ext, $ext_file );
170 1 push @auth_plugins, collect_auth_plugins( $ext->{authPlugin}, $ext_file );
171 }
172  
173 # Warn on conflicting authPlugin declarations (same k with a different v
174 # or a different role set across extension files). Dedup below keeps only
175 # the first-seen label, so flag the conflict to the maintainer.
176 1 warn_auth_plugin_conflicts( \@auth_plugins );
177  
178 # Apply auth plugin declarations to the initial merged attributes so the
179 # diff-based extraction below also picks up auth-plugin-driven additions.
180 # This initial pass also populates nested authChoiceModules; auth plugins
181 # are re-applied again at call time via @auth_plugins on fresh Build.pm
182 # data so nested-select changes survive dclone().
183 1 apply_auth_plugins( $attributes, \@auth_plugins );
184  
185 # 3. Store extension data for merging at call time
186 # Build.pm modifies data in place, so we need fresh copies each time
187 1 verbose "Patching Build modules with merged data...\n";
188  
189 # Store only the EXTENSION data (not the full merged data)
190 1 my $ext_attributes = {};
191 1 my $ext_tree = {};
192 1 my $ext_ctrees = {};
193 1 my $ext_constants = {};
194 1 my $ext_lang = {};
195  
196 # Extract extensions by comparing with original
197 1 my $orig_attrs = Lemonldap::NG::Manager::Build::Attributes::attributes();
198 1 my $orig_attr_keys = { map { $_ => 1 } keys %$orig_attrs };
199  
200 # Store select append operations separately (for existing attributes with
201 # new select options added by extensions)
202 1 my $ext_select_appends = {};
203  
204 1 for my $key ( keys %$attributes ) {
205 1019 ▶ if ( $orig_attr_keys->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orig_attr_keys->{$key}) { } 1017 2 1019
206  
207 # Check if select options were appended to an existing attribute
208 1017 ▶ if ( ref $orig_attrs->{$key} eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $orig_attrs->{$key} eq "HASH" and ref $attributes->{$key} eq "HASH" and ref $orig_attrs->{$key}{"select"} eq "ARRAY" and ref $attributes->{$key}{"select"} eq "ARRAY") 69 948 1017
Condition55%5/9
ref $orig_attrs->{$key} eq "HASH" and ref $attributes->{$key} eq "HASH" and ref $orig_attrs->{$key}{"select"} eq "ARRAY" and ref $attributes->{$key}{"select"} eq "ARRAY"
!ll&&!rl&&r
948069
ref $orig_attrs->{$key} eq "HASH" and ref $attributes->{$key} eq "HASH" and ref $orig_attrs->{$key}{"select"} eq "ARRAY"
!ll&&!rl&&r
094869
ref $orig_attrs->{$key} eq "HASH" and ref $attributes->{$key} eq "HASH"
!ll&&!rl&&r
001017
MC/DC25%1/4
ref $orig_attrs->{$key} eq "HASH" and ref $attributes->{$key} eq "HASH" and ref $orig_attrs->{$key}{"select"} eq "ARRAY" and ref $attributes->{$key}{"select"} eq "ARRAY"
ref $orig_attrs->{$key} eq "HASH" ref $attributes->{$key} eq "HASH" ref $orig_attrs->{$key}{"select"} eq "ARRAY" ref $attributes->{$key}{"select"} eq "ARRAY"
Truth table40%2/5
A and B and C and D
A= ref $orig_attrs->{$key} eq "HASH"B= ref $attributes->{$key} eq "HASH"C= ref $orig_attrs->{$key}{"select"} eq "ARRAY"D= ref $attributes->{$key}{"select"} eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
209 && ref $attributes->{$key} eq 'HASH'
210 && ref $orig_attrs->{$key}{select} eq 'ARRAY'
211 && ref $attributes->{$key}{select} eq 'ARRAY' )
212 {
213 my %orig_keys =
214 418 map { $_->{k} => 1 }
215 421 ▶ grep { ref $_ eq 'HASH' && exists $_->{k} }
Condition66%2/3
ref $_ eq 'HASH' && exists $_->{'k'}
!ll&&!rl&&r
30418
MC/DC50%1/2
ref $_ eq 'HASH' && exists $_->{'k'}
ref $_ eq 'HASH' exists $_->{'k'}
Truth table66%2/3
A && B
A= ref $_ eq 'HASH'B= exists $_->{'k'}
ABresult
0X0
100
111
216 69 @{ $orig_attrs->{$key}{select} };
217 my @new_opts =
218 422 ▶ grep { ref $_ eq 'HASH' && $_->{k} && !$orig_keys{ $_->{k} } }
Condition100%6/6
ref $_ eq 'HASH' && $_->{'k'} && !$orig_keys{$_->{'k'}}
!ll&&!rl&&r
303911
ref $_ eq "HASH" and $_->{"k"}
!ll&&!rl&&r
327392
MC/DC100%3/3
ref $_ eq 'HASH' && $_->{'k'} && !$orig_keys{$_->{'k'}}
ref $_ eq "HASH" $_->{"k"} !$orig_keys{$_->{'k'}}
Truth table100%4/4
A and B && not(C)
A= ref $_ eq "HASH"B= $_->{"k"}C= !$orig_keys{$_->{'k'}}
ABCresult
0XX0
10X0
1100
1111
219 69 @{ $attributes->{$key}{select} };
220 69 ▶ $ext_select_appends->{$key} = \@new_opts if @new_opts;
Branch: 1 branch
BranchTrueFalseTotal
if @new_opts 1 68 69
221 }
222 }
223 else {
224 2 $ext_attributes->{$key} = $attributes->{$key};
225 }
226 }
227  
228 # For tree: store extension modifications to replay on each fresh copy
229 # We need to re-apply extensions to fresh tree data because Build.pm modifies the tree in place
230 # (e.g., $leaf =~ s/^\*// removes * prefix on first scan)
231 1 my @tree_extensions;
232 1 for my $ext_file (@ext_files) {
233 1 my $ext = load_extension($ext_file);
234 1 ▶ if ( $ext->{tree} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext->{"tree"}) 1 0 1
235 my @trees =
236 0 ▶ ref $ext->{tree} eq 'ARRAY' ? @{ $ext->{tree} } : ( $ext->{tree} );
Branch: 1 branch
BranchTrueFalseTotal
ref $ext->{'tree'} eq 'ARRAY' ? : 0 1 1
237 1 for my $t (@trees) {
238 1 ▶ push @tree_extensions, { ext => $t, file => $ext_file }
Branch: 1 branch
BranchTrueFalseTotal
if $t and %$t 1 0 1
Condition33%1/3
$t and %$t
!ll&&!rl&&r
001
MC/DC0%0/2
$t and %$t
$t %$t
Truth table33%1/3
A and B
A= $tB= %$t
ABresult
0X0
100
111
239 if $t && %$t;
240 }
241 }
242 1 ▶ for my $ctree_name ( keys %{ $ext->{ctrees} || {} } ) {
Condition50%1/2
$ext->{'ctrees'} || {}
l!l
10
MC/DC0%0/1
$ext->{'ctrees'} || {}
$ext->{'ctrees'}
Truth table50%1/2
A
A= $ext->{'ctrees'}
Aresult
11
00
243 1 my $spec = $ext->{ctrees}{$ctree_name};
244 1 ▶ my @specs = ref $spec eq 'ARRAY' ? @$spec : ($spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $spec eq 'ARRAY' ? : 0 1 1
245 1 for my $s (@specs) {
246 1 push @{ $ext_ctrees->{$ctree_name} },
247 { ext => $s, file => $ext_file };
248 }
249 }
250  
251 # Collect translations
252 1 ▶ if ( $ext->{lang} && %{ $ext->{lang} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext->{"lang"} and %{$ext->{"lang"};}) 1 0 1
Condition33%1/3
$ext->{"lang"} and %{$ext->{"lang"};}
!ll&&!rl&&r
001
MC/DC0%0/2
$ext->{"lang"} and %{$ext->{"lang"};}
$ext->{"lang"} %{$ext->{"lang"};}
Truth table33%1/3
A and B
A= $ext->{"lang"}B= %{$ext->{"lang"};}
ABresult
0X0
100
111
253 1 for my $key ( keys %{ $ext->{lang} } ) {
254 2 ▶ if ( exists $ext_lang->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ext_lang->{$key}) 0 2 2
255 0 warn "Warning [$ext_file]: Overriding translation key '$key'\n";
256 }
257 2 $ext_lang->{$key} = $ext->{lang}{$key};
258 2 verbose " Added translation: $key\n";
259 }
260 }
261 }
262  
263 # Save original functions
264 1 my $orig_attributes = \&Lemonldap::NG::Manager::Build::Attributes::attributes;
265 1 my $orig_tree = \&Lemonldap::NG::Manager::Build::Tree::tree;
266 1 my $orig_ctrees = \&Lemonldap::NG::Manager::Build::CTrees::cTrees;
267 1 my $orig_constants =
268 \&Lemonldap::NG::Manager::Build::PortalConstants::portalConstants;
269  
270 {
271 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
272  
273 0 ▶ *Lemonldap::NG::Manager::Build::Attributes::attributes = sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
274 0 my $fresh = $orig_attributes->();
275  
276 # Merge extension attributes (new attributes)
277 0 for my $key ( keys %$ext_attributes ) {
278 0 $fresh->{$key} = $ext_attributes->{$key};
279 }
280  
281 # Apply select appends (new options added to existing select attributes)
282 0 for my $key ( keys %$ext_select_appends ) {
283 0 ▶ if ( ref $fresh->{$key} eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fresh->{$key} eq "HASH" and ref $fresh->{$key}{"select"} eq "ARRAY") 0 0 0
Condition0%0/3
ref $fresh->{$key} eq "HASH" and ref $fresh->{$key}{"select"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $fresh->{$key} eq "HASH" and ref $fresh->{$key}{"select"} eq "ARRAY"
ref $fresh->{$key} eq "HASH" ref $fresh->{$key}{"select"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $fresh->{$key} eq "HASH"B= ref $fresh->{$key}{"select"} eq "ARRAY"
ABresult
0X0
100
111
284 && ref $fresh->{$key}{select} eq 'ARRAY' )
285 {
286 my %existing =
287 0 map { $_->{k} => 1 }
288 0 ▶ grep { ref $_ eq 'HASH' && exists $_->{k} }
Condition0%0/3
ref $_ eq 'HASH' && exists $_->{'k'}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ eq 'HASH' && exists $_->{'k'}
ref $_ eq 'HASH' exists $_->{'k'}
Truth table0%0/3
A && B
A= ref $_ eq 'HASH'B= exists $_->{'k'}
ABresult
0X0
100
111
289 0 @{ $fresh->{$key}{select} };
290 0 for my $opt ( @{ $ext_select_appends->{$key} } ) {
291 0 push @{ $fresh->{$key}{select} }, $opt
292 0 ▶ unless $existing{ $opt->{k} };
Branch: 1 branch
BranchTrueFalseTotal
unless $existing{$opt->{"k"}} 0 0 0
293 }
294 }
295 }
296  
297 # Apply authPlugin declarations (fills authentication / userDB /
298 # passwordDB / authChoiceModules / combModules selects based on
299 # declared roles). Safe to re-run: each append is deduplicated.
300 0 apply_auth_plugins( $fresh, \@auth_plugins );
301  
302 0 return $fresh;
303 1 };
304  
305 # For tree: return a fresh deep copy and re-apply extensions each time
306 # This is necessary because Build.pm modifies the tree in place
307 # (e.g., scanTree does $leaf =~ s/^\*// which removes * prefix)
308 0 ▶ *Lemonldap::NG::Manager::Build::Tree::tree = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
309 0 my $fresh = dclone( $orig_tree->() );
310 0 for my $ext_info (@tree_extensions) {
311 0 merge_tree( $fresh, $ext_info->{ext}, $ext_info->{file} );
312 }
313 0 return $fresh;
314 1 };
315  
316 # For ctrees: also return fresh deep copy since scanTree is called on each ctree node
317 0 ▶ *Lemonldap::NG::Manager::Build::CTrees::cTrees = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
318 0 my $fresh = dclone( $orig_ctrees->() );
319 0 for my $ctree_name ( keys %$ext_ctrees ) {
320 0 for my $ext_info ( @{ $ext_ctrees->{$ctree_name} } ) {
321 apply_ctree_extension( $fresh, $ctree_name, $ext_info->{ext},
322 0 $ext_info->{file} );
323 }
324 }
325 0 return $fresh;
326 1 };
327  
328 *Lemonldap::NG::Manager::Build::PortalConstants::portalConstants =
329 0 ▶ sub { $constants };
Subroutine __ANON__: not called CC=1 SCAR=1.2
330 }
331  
332 # 4. Load Build.pm (modules are already loaded, functions are patched)
333 1 require Lemonldap::NG::Manager::Build;
334  
335 # 5a. Preserve DEFAULTCONFFILE and dirName from installed Constants.pm
336 # These values may have been customized by Makefile.PL (via LMNGCONFFILE
337 # and LMNGCONFDIR env vars). Build.pm regenerates Constants.pm with
338 # hardcoded defaults, so we read the current values and restore them after.
339 0 my ( $saved_conffile, $saved_dirname );
340 0 ▶if ( $conf_constants_file ne '/dev/null' && -r $conf_constants_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_constants_file ne "/dev/null" and -r $conf_constants_file) 0 0 0
Condition0%0/3
$conf_constants_file ne "/dev/null" and -r $conf_constants_file
!ll&&!rl&&r
000
MC/DC0%0/2
$conf_constants_file ne "/dev/null" and -r $conf_constants_file
$conf_constants_file ne "/dev/null" -r $conf_constants_file
Truth table0%0/3
A and B
A= $conf_constants_file ne "/dev/null"B= -r $conf_constants_file
ABresult
0X0
100
111
341 0 open my $fh, '<', $conf_constants_file;
342 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
343 0 ▶ if (/^use constant DEFAULTCONFFILE\s*=>\s*"(.+)"\s*;/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^use constant DEFAULTCONFFILE\s*=>\s*"(.+)"\s*;/) { } 0 0 0
elsif (/^\s*dirName\s*=>\s*'(.+)'\s*,/) { } 0 0 0
344 0 $saved_conffile = $1;
345 }
346 elsif (/^\s*dirName\s*=>\s*'(.+)'\s*,/) {
347 0 $saved_dirname = $1;
348 }
349 }
350 0 close $fh;
351 0 ▶ verbose " Preserved DEFAULTCONFFILE=$saved_conffile\n" if $saved_conffile;
Branch: 1 branch
BranchTrueFalseTotal
if $saved_conffile 0 0 0
352 0 ▶ verbose " Preserved dirName=$saved_dirname\n" if $saved_dirname;
Branch: 1 branch
BranchTrueFalseTotal
if $saved_dirname 0 0 0
353 }
354  
355 # 5b. Redirect output files to /dev/null when their parent directory does not
356 # exist (component not installed locally, e.g. portal or handler absent)
357 0 for my $ref (
358 \$struct_file, \$conftree_file,
359 \$manager_constants_file, \$manager_attributes_file,
360 \$default_values_file, \$conf_constants_file,
361 \$reverse_tree_file, \$portal_constants_file,
362 \$handler_status_constants_file,
363 )
364 {
365 0 ▶ if ( $$ref ne '/dev/null' && !-d dirname($$ref) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ref ne "/dev/null" and not -d dirname($$ref)) 0 0 0
Condition0%0/3
$$ref ne "/dev/null" and not -d dirname($$ref)
!ll&&!rl&&r
000
MC/DC0%0/2
$$ref ne "/dev/null" and not -d dirname($$ref)
$$ref ne "/dev/null" not -d dirname($$ref)
Truth table0%0/3
A and not(B)
A= $$ref ne "/dev/null"B= not -d dirname($$ref)
ABresult
0X0
100
111
366 0 verbose " Skipping $$ref (parent directory does not exist)\n";
367 0 $$ref = '/dev/null';
368 }
369 }
370  
371 # 6. Call Build.pm::run()
372 0 verbose "Running Build.pm to generate files...\n";
373 0 Lemonldap::NG::Manager::Build->run(
374 structFile => $struct_file,
375 confTreeFile => $conftree_file,
376 managerConstantsFile => $manager_constants_file,
377 managerAttributesFile => $manager_attributes_file,
378 defaultValuesFile => $default_values_file,
379 confConstantsFile => $conf_constants_file,
380 firstLmConfFile => $first_lmconf_file,
381 reverseTreeFile => $reverse_tree_file,
382 portalConstantsFile => $portal_constants_file,
383 handlerStatusConstantsFile => $handler_status_constants_file,
384 docConstantsFile => $doc_constants_file,
385 );
386  
387 # 6a. Restore preserved DEFAULTCONFFILE and dirName in Constants.pm
388 0 ▶if ( $conf_constants_file ne '/dev/null'
Branch: 1 branch
BranchTrueFalseTotal
if ($conf_constants_file ne "/dev/null" and $saved_conffile || $saved_dirname) 0 0 0
Condition0%0/6
$conf_constants_file ne "/dev/null" and $saved_conffile || $saved_dirname
!ll&&!rl&&r
000
$saved_conffile or $saved_dirname
l!l&&r!l&&!r
000
MC/DC0%0/3
$conf_constants_file ne "/dev/null" and $saved_conffile || $saved_dirname
$conf_constants_file ne "/dev/null" $saved_conffile $saved_dirname
Truth table0%0/4
A and B or C
A= $conf_constants_file ne "/dev/null"B= $saved_conffileC= $saved_dirname
ABCresult
0XX0
1000
11X1
1011
389 && ( $saved_conffile || $saved_dirname ) )
390 {
391 0 ▶ open my $fh, '<', $conf_constants_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $conf_constants_file or die "Cannot read ${conf_constants_file}: $!" 0 0 0
392 or die "Cannot read $conf_constants_file: $!";
393 0 my $content = do { local $/; <$fh> };
394 0 close $fh;
395  
396 0 my $modified = 0;
397 0 ▶ if ( $saved_conffile
Branch: 1 branch
BranchTrueFalseTotal
if ($saved_conffile and $content =~ s/^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)/$1$saved_conffile$2/m) 0 0 0
Condition0%0/3
$saved_conffile and $content =~ s/^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)/$1$saved_conffile$2/m
!ll&&!rl&&r
000
MC/DC0%0/2
$saved_conffile and $content =~ s/^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)/$1$saved_conffile$2/m
$saved_conffile $content =~ s/^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)/$1$saved_conffile$2/m
Truth table0%0/3
A and B
A= $saved_conffileB= $content =~ s/^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)/$1$saved_conffile$2/m
ABresult
0X0
100
111
398 && $content =~
399 s{^(use constant DEFAULTCONFFILE\s*=>\s*").*("\s*;)}{$1$saved_conffile$2}m
400 )
401 {
402 0 $modified = 1;
403 0 verbose " Restored DEFAULTCONFFILE=$saved_conffile\n";
404 }
405 0 ▶ if ( $saved_dirname
Branch: 1 branch
BranchTrueFalseTotal
if ($saved_dirname and $content =~ s/^(\s*dirName\s*=>\s*').*('\s*,)/$1$saved_dirname$2/m) 0 0 0
Condition0%0/3
$saved_dirname and $content =~ s/^(\s*dirName\s*=>\s*').*('\s*,)/$1$saved_dirname$2/m
!ll&&!rl&&r
000
MC/DC0%0/2
$saved_dirname and $content =~ s/^(\s*dirName\s*=>\s*').*('\s*,)/$1$saved_dirname$2/m
$saved_dirname $content =~ s/^(\s*dirName\s*=>\s*').*('\s*,)/$1$saved_dirname$2/m
Truth table0%0/3
A and B
A= $saved_dirnameB= $content =~ s/^(\s*dirName\s*=>\s*').*('\s*,)/$1$saved_dirname$2/m
ABresult
0X0
100
111
406 && $content =~ s{^(\s*dirName\s*=>\s*').*('\s*,)}{$1$saved_dirname$2}m )
407 {
408 0 $modified = 1;
409 0 verbose " Restored dirName=$saved_dirname\n";
410 }
411  
412 0 ▶ if ($modified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified) 0 0 0
413 0 ▶ open my $out, '>', $conf_constants_file
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $conf_constants_file or die "Cannot write ${conf_constants_file}: $!" 0 0 0
414 or die "Cannot write $conf_constants_file: $!";
415 0 print $out $content;
416 0 close $out;
417 }
418 }
419  
420 # 6b. Minify conftree.js
421 0 ▶if ( $conftree_file ne '/dev/null' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conftree_file ne '/dev/null') { } 0 0 0
422 0 minify_conftree($conftree_file);
423 }
424 else {
425 0 verbose "Skipping minification (conftree.js not generated)\n";
426 }
427  
428 # 7. Update language files with translations from extensions
429 0 ▶if ( %$ext_lang && -d $lang_dir ) {
Branch: 2 branches
BranchTrueFalseTotal
if (%$ext_lang and -d $lang_dir) { } 0 0 0
elsif (%$ext_lang) { } 0 0 0
Condition0%0/3
%$ext_lang and -d $lang_dir
!ll&&!rl&&r
000
MC/DC0%0/2
%$ext_lang and -d $lang_dir
%$ext_lang -d $lang_dir
Truth table0%0/3
A and B
A= %$ext_langB= -d $lang_dir
ABresult
0X0
100
111
430 0 verbose "Updating language files in $lang_dir...\n";
431 0 update_language_files( $lang_dir, $ext_lang );
432 }
433 elsif (%$ext_lang) {
434 0 warn "Warning: Language directory not found: $lang_dir\n";
435 0 warn " Translations from extensions will not be applied.\n";
436 }
437  
438 0 verbose "Build completed successfully.\n";
439  
440 0 exit 0;
441  
442 #
443 # Helper functions
444 #
445  
446 2 ▶sub load_extension {
Subroutine load_extension: called CC=3 SCAR=13.6
447 2 my ($file) = @_;
448  
449 2 my $ext;
450 2 ▶ if ( $file =~ /\.json$/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.json$/i) { } 2 0 2
elsif ($file =~ /\.pm$/i) { } 0 0 0
451 2 $ext = load_json_extension($file);
452 }
453 elsif ( $file =~ /\.pm$/i ) {
454 0 $ext = load_perl_extension($file);
455 }
456 else {
457 0 warn "Unknown extension file type: $file\n";
458 0 return {};
459 }
460 2 compile_attribute_tests( $ext->{attributes}, $file );
461 2 return $ext;
462 }
463  
464 # Manager::Conf::Parser::_execTest() only accepts a Regexp ref, a code ref
465 # or a hash ref for `test` / `keyTest`; a plain string makes it die at
466 # configuration save time with:
467 # Malformed test for <attr>/<key>: only regexp ref or sub are accepted
468 # JSON extensions cannot carry a qr// so they express those tests as
469 # strings; compile them here (a .pm extension may also use a string).
470 2 ▶sub compile_attribute_tests {
Subroutine compile_attribute_tests: called CC=8 SCAR=29.0
471 2 my ( $attributes, $file ) = @_;
472 2 ▶ return unless ref $attributes eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attributes eq "HASH" 0 2 2
473  
474 2 for my $name ( sort keys %$attributes ) {
475 6 my $attr = $attributes->{$name};
476 6 ▶ next unless ref $attr eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attr eq "HASH" 0 6 6
477 6 for my $field (qw(test keyTest)) {
478 12 my $value = $attr->{$field};
479 12 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 12 0 12
480 0 ▶ next if ref $value; # already a Regexp / CODE / HASH ref
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
481 0 my $re = eval { qr/$value/ };
482 0 ▶ die "Error [$file]: $name: invalid regexp in '$field': $@"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
483 if $@;
484 0 $attr->{$field} = $re;
485 0 verbose " Compiled $name/$field as regexp\n";
486 }
487 }
488 }
489  
490 2 ▶sub load_json_extension {
Subroutine load_json_extension: called CC=7 SCAR=21.5
491 2 my ($file) = @_;
492  
493 2 ▶ open my $fh, '<', $file or die "Cannot open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Cannot open ${file}: $!" 2 0 2
494 2 local $/;
495 2 my $content = <$fh>;
496 2 close $fh;
497  
498 2 my $data = JSON->new->utf8->decode($content);
499 return {
500 attributes => $data->{attributes} || {},
501 tree => $data->{tree} || {},
502 ctrees => $data->{ctrees} || {},
503 constants => $data->{constants} || {},
504 lang => $data->{lang} || {},
505 authPlugin => $data->{authPlugin},
506 2 ▶ };
Condition50%5/10
$data->{'attributes'} || {}
l!l
20
$data->{'tree'} || {}
l!l
20
$data->{'ctrees'} || {}
l!l
20
$data->{'constants'} || {}
l!l
20
$data->{'lang'} || {}
l!l
20
MC/DC0%0/1
$data->{'attributes'} || {}
$data->{'attributes'}
MC/DC0%0/1
$data->{'tree'} || {}
$data->{'tree'}
MC/DC0%0/1
$data->{'ctrees'} || {}
$data->{'ctrees'}
MC/DC0%0/1
$data->{'constants'} || {}
$data->{'constants'}
MC/DC0%0/1
$data->{'lang'} || {}
$data->{'lang'}
Truth table50%1/2
A
A= $data->{'attributes'}
Aresult
11
00
Truth table50%1/2
A
A= $data->{'tree'}
Aresult
11
00
Truth table50%1/2
A
A= $data->{'ctrees'}
Aresult
11
00
Truth table50%1/2
A
A= $data->{'constants'}
Aresult
11
00
Truth table50%1/2
A
A= $data->{'lang'}
Aresult
11
00
507 }
508  
509 0 ▶sub load_perl_extension {
Subroutine load_perl_extension: not called CC=10 SCAR=44.0
510 0 my ($file) = @_;
511  
512 # Read the file content to find the package name
513 0 my $content = do {
514 0 ▶ open my $fh, '<', $file or die "Cannot open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Cannot open ${file}: $!" 0 0 0
515 0 local $/;
516 0 <$fh>;
517 };
518  
519 # Extract package name from the file
520 0 my ($pkg) = $content =~ /^\s*package\s+([\w:]+)\s*;/m;
521  
522 0 ▶ unless ($pkg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg) 0 0 0
523  
524 # If no package declaration, create one with a unique name
525 0 $pkg = $file;
526 0 $pkg =~ s/[^a-zA-Z0-9]/_/g;
527 0 $pkg = "LLNGExtension::$pkg";
528 0 $content = "package $pkg;\n$content";
529 }
530  
531 # Eval the code
532 0 eval $content;
533 0 ▶ die "Error loading $file: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
534  
535 # Extract data from the extension module
536 0 my $ext = {};
537  
538 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
539 $ext->{attributes} =
540 0 ▶ defined &{"${pkg}::attributes"} ? &{"${pkg}::attributes"}() : {};
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::attributes";} ? : 0 0 0
541 0 ▶ $ext->{tree} = defined &{"${pkg}::tree"} ? &{"${pkg}::tree"}() : {};
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::tree";} ? : 0 0 0
542 0 ▶ $ext->{ctrees} = defined &{"${pkg}::ctrees"} ? &{"${pkg}::ctrees"}() : {};
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::ctrees";} ? : 0 0 0
543 $ext->{constants} =
544 0 ▶ defined &{"${pkg}::constants"} ? &{"${pkg}::constants"}() : {};
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::constants";} ? : 0 0 0
545 0 ▶ $ext->{lang} = defined &{"${pkg}::lang"} ? &{"${pkg}::lang"}() : {};
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::lang";} ? : 0 0 0
546 $ext->{authPlugin} =
547 0 ▶ defined &{"${pkg}::authPlugin"} ? &{"${pkg}::authPlugin"}() : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined &{"${pkg}::authPlugin";} ? : 0 0 0
548 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
549  
550 0 return $ext;
551 }
552  
553 # Normalize an extension's `authPlugin` entry into a list of
554 # { k, v, roles, file } hashes. Accepts a single hash or an array of hashes.
555 1 ▶sub collect_auth_plugins {
Subroutine collect_auth_plugins: called CC=11 SCAR=46.8
556 1 my ( $raw, $ext_file ) = @_;
557 1 ▶ return () unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 1 0 1
558  
559 0 ▶ my @entries = ref $raw eq 'ARRAY' ? @$raw : ($raw);
Branch: 1 branch
BranchTrueFalseTotal
ref $raw eq 'ARRAY' ? : 0 0 0
560 0 my @out;
561 0 for my $entry (@entries) {
562 0 ▶ unless ( ref $entry eq 'HASH' && $entry->{k} && $entry->{v} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $entry eq "HASH" and $entry->{"k"} and $entry->{"v"}) 0 0 0
Condition0%0/6
ref $entry eq "HASH" and $entry->{"k"} and $entry->{"v"}
!ll&&!rl&&r
000
ref $entry eq "HASH" and $entry->{"k"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $entry eq "HASH" and $entry->{"k"} and $entry->{"v"}
ref $entry eq "HASH" $entry->{"k"} $entry->{"v"}
Truth table0%0/4
A and B and C
A= ref $entry eq "HASH"B= $entry->{"k"}C= $entry->{"v"}
ABCresult
0XX0
10X0
1100
1111
563 0 warn
564 "Warning [$ext_file]: authPlugin entries must have 'k' and 'v' keys\n";
565 0 next;
566 }
567 my $roles =
568 ref $entry->{roles} eq 'ARRAY' ? $entry->{roles}
569 0 ▶ : $entry->{roles} ? [ $entry->{roles} ]
Branch: 2 branches
BranchTrueFalseTotal
ref $entry->{'roles'} eq 'ARRAY' ? : 0 0 0
$entry->{'roles'} ? : 0 0 0
570 : [];
571 0 ▶ unless (@$roles) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$roles) 0 0 0
572 0 warn
573 "Warning [$ext_file]: authPlugin '$entry->{k}' declares no roles\n";
574 0 next;
575 }
576 0 my %valid = map { $_ => 1 } qw(authentication userDB passwordDB);
577 0 my @bad = grep { !$valid{$_} } @$roles;
578 0 ▶ if (@bad) {
Branch: 1 branch
BranchTrueFalseTotal
if (@bad) 0 0 0
579 0 warn "Warning [$ext_file]: authPlugin '$entry->{k}' has "
580 . "unknown role(s): @bad (allowed: authentication, userDB, passwordDB)\n";
581 }
582 push @out,
583 {
584 k => $entry->{k},
585 v => $entry->{v},
586 0 roles => [ grep { $valid{$_} } @$roles ],
587 file => $ext_file,
588 };
589 }
590 0 return @out;
591 }
592  
593 # Mutate $attrs so the given auth plugins appear in the right select lists:
594 # authentication role -> authentication.select, authChoiceModules.select[0], combModules.select
595 # userDB role -> userDB.select, authChoiceModules.select[1], combModules.select
596 # passwordDB role -> passwordDB.select, authChoiceModules.select[2]
597 # All appends dedupe on the `k` key so re-running is safe.
598 1 ▶sub apply_auth_plugins {
Subroutine apply_auth_plugins: called CC=8 SCAR=37.5
599 1 my ( $attrs, $plugins ) = @_;
600 1 ▶ return unless $attrs && $plugins && @$plugins;
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs and $plugins and @$plugins 1 0 1
Condition33%2/6
$attrs and $plugins and @$plugins
!ll&&!rl&&r
010
$attrs and $plugins
!ll&&!rl&&r
001
MC/DC0%0/3
$attrs and $plugins and @$plugins
$attrs $plugins @$plugins
Truth table25%1/4
A and B and C
A= $attrsB= $pluginsC= @$plugins
ABCresult
0XX0
10X0
1100
1111
601  
602 0 my %role_to_flat = (
603 authentication => 'authentication',
604 userDB => 'userDB',
605 passwordDB => 'passwordDB',
606 );
607 0 my %role_to_choice_idx = (
608 authentication => 0,
609 userDB => 1,
610 passwordDB => 2,
611 );
612  
613 0 for my $plugin (@$plugins) {
614 0 my $opt = { k => $plugin->{k}, v => $plugin->{v} };
615 0 my %roles = map { $_ => 1 } @{ $plugin->{roles} };
616  
617 0 for my $role ( keys %roles ) {
618 0 _append_flat_select( $attrs, $role_to_flat{$role}, $opt );
619 _append_nested_select( $attrs, 'authChoiceModules',
620 0 $role_to_choice_idx{$role}, $opt );
621 }
622  
623 # combModules only covers authentication and userDB roles
624 0 ▶ if ( $roles{authentication} || $roles{userDB} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($roles{"authentication"} or $roles{"userDB"}) 0 0 0
Condition0%0/3
$roles{"authentication"} or $roles{"userDB"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$roles{"authentication"} or $roles{"userDB"}
$roles{"authentication"} $roles{"userDB"}
Truth table0%0/3
A or B
A= $roles{"authentication"}B= $roles{"userDB"}
ABresult
1X1
011
000
625 0 _append_flat_select( $attrs, 'combModules', $opt );
626 }
627 }
628 }
629  
630 1 ▶sub warn_auth_plugin_conflicts {
Subroutine warn_auth_plugin_conflicts: called CC=5 SCAR=30.3
631 1 my ($plugins) = @_;
632 1 my %seen;
633 1 for my $p (@$plugins) {
634 0 my $prev = $seen{ $p->{k} };
635 0 ▶ unless ($prev) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prev) 0 0 0
636 0 $seen{ $p->{k} } = $p;
637 0 next;
638 }
639 0 ▶ if ( $prev->{v} ne $p->{v} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev->{"v"} ne $p->{"v"}) 0 0 0
640 0 warn "Warning [$p->{file}]: authPlugin '$p->{k}' label differs "
641 . "from earlier declaration in $prev->{file} "
642 . "('$p->{v}' vs '$prev->{v}'); keeping '$prev->{v}'\n";
643 }
644 0 my $prev_roles = join ',', sort @{ $prev->{roles} };
645 0 my $curr_roles = join ',', sort @{ $p->{roles} };
646 0 ▶ if ( $prev_roles ne $curr_roles ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_roles ne $curr_roles) 0 0 0
647 0 warn "Warning [$p->{file}]: authPlugin '$p->{k}' roles differ "
648 . "from earlier declaration in $prev->{file} "
649 . "($curr_roles vs $prev_roles); union will be applied\n";
650 }
651 }
652 }
653  
654 0 ▶sub _append_flat_select {
Subroutine _append_flat_select: not called CC=7 SCAR=40.3
655 0 my ( $attrs, $key, $opt ) = @_;
656 0 ▶ return unless ref $attrs->{$key} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs->{$key} eq "HASH" 0 0 0
657 0 ▶ return unless ref $attrs->{$key}{select} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs->{$key}{"select"} eq "ARRAY" 0 0 0
658 0 for my $existing ( @{ $attrs->{$key}{select} } ) {
659 return
660 if ref $existing eq 'HASH'
661 && defined $existing->{k}
662 0 ▶ && $existing->{k} eq $opt->{k};
Branch: 1 branch
BranchTrueFalseTotal
if ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"} 0 0 0
Condition0%0/6
ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"}
!ll&&!rl&&r
000
ref $existing eq "HASH" and defined $existing->{"k"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"}
ref $existing eq "HASH" defined $existing->{"k"} $existing->{"k"} eq $opt->{"k"}
Truth table0%0/4
A and B and C
A= ref $existing eq "HASH"B= defined $existing->{"k"}C= $existing->{"k"} eq $opt->{"k"}
ABCresult
0XX0
10X0
1100
1111
663 }
664 0 push @{ $attrs->{$key}{select} }, {%$opt};
665 }
666  
667 0 ▶sub _append_nested_select {
Subroutine _append_nested_select: not called CC=8 SCAR=42.8
668 0 my ( $attrs, $key, $idx, $opt ) = @_;
669 0 ▶ return unless ref $attrs->{$key} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs->{$key} eq "HASH" 0 0 0
670 0 ▶ return unless ref $attrs->{$key}{select} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs->{$key}{"select"} eq "ARRAY" 0 0 0
671 0 ▶ return unless ref $attrs->{$key}{select}[$idx] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $attrs->{$key}{"select"}[$idx] eq "ARRAY" 0 0 0
672 0 for my $existing ( @{ $attrs->{$key}{select}[$idx] } ) {
673 return
674 if ref $existing eq 'HASH'
675 && defined $existing->{k}
676 0 ▶ && $existing->{k} eq $opt->{k};
Branch: 1 branch
BranchTrueFalseTotal
if ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"} 0 0 0
Condition0%0/6
ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"}
!ll&&!rl&&r
000
ref $existing eq "HASH" and defined $existing->{"k"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $existing eq "HASH" and defined $existing->{"k"} and $existing->{"k"} eq $opt->{"k"}
ref $existing eq "HASH" defined $existing->{"k"} $existing->{"k"} eq $opt->{"k"}
Truth table0%0/4
A and B and C
A= ref $existing eq "HASH"B= defined $existing->{"k"}C= $existing->{"k"} eq $opt->{"k"}
ABCresult
0XX0
10X0
1100
1111
677 }
678 0 push @{ $attrs->{$key}{select}[$idx] }, {%$opt};
679 }
680  
681 1 ▶sub merge_extension {
Subroutine merge_extension: called CC=9 SCAR=26.1
682 1 my ( $core_attrs, $core_tree, $core_ctrees, $core_constants, $ext,
683 $ext_file )
684 = @_;
685  
686 # Merge attributes (simple hash merge)
687 1 merge_attributes( $core_attrs, $ext->{attributes}, $ext_file );
688  
689 # Merge tree (insert nodes at specified path)
690 # Support both single hash and array of hashes
691 1 ▶ if ( $ext->{tree} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ext->{"tree"}) 1 0 1
692 my @trees =
693 0 ▶ ref $ext->{tree} eq 'ARRAY' ? @{ $ext->{tree} } : ( $ext->{tree} );
Branch: 1 branch
BranchTrueFalseTotal
ref $ext->{'tree'} eq 'ARRAY' ? : 0 1 1
694 1 for my $t (@trees) {
695 1 ▶ merge_tree( $core_tree, $t, $ext_file ) if $t && %$t;
Branch: 1 branch
BranchTrueFalseTotal
if $t and %$t 1 0 1
Condition33%1/3
$t and %$t
!ll&&!rl&&r
001
MC/DC0%0/2
$t and %$t
$t %$t
Truth table33%1/3
A and B
A= $tB= %$t
ABresult
0X0
100
111
696 }
697 }
698  
699 # Merge ctrees (insert into specific node templates)
700 merge_ctrees( $core_ctrees, $ext->{ctrees}, $ext_file )
701 1 ▶ if $ext->{ctrees} && %{ $ext->{ctrees} };
Branch: 1 branch
BranchTrueFalseTotal
if $ext->{"ctrees"} and %{$ext->{"ctrees"};} 1 0 1
Condition33%1/3
$ext->{"ctrees"} and %{$ext->{"ctrees"};}
!ll&&!rl&&r
001
MC/DC0%0/2
$ext->{"ctrees"} and %{$ext->{"ctrees"};}
$ext->{"ctrees"} %{$ext->{"ctrees"};}
Truth table33%1/3
A and B
A= $ext->{"ctrees"}B= %{$ext->{"ctrees"};}
ABresult
0X0
100
111
702  
703 # Merge constants (with validation)
704 merge_constants( $core_constants, $ext->{constants}, $ext_file )
705 1 ▶ if $ext->{constants};
Branch: 1 branch
BranchTrueFalseTotal
if $ext->{"constants"} 1 0 1
706 }
707  
708 1 ▶sub merge_attributes {
Subroutine merge_attributes: called CC=12 SCAR=28.5
709 1 my ( $core, $ext, $ext_file ) = @_;
710  
711 1 for my $key ( keys %$ext ) {
712 3 ▶ if ( exists $core->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $core->{$key}) 1 2 3
713  
714 # If both core and extension have a 'select' array, append new
715 # options instead of replacing the entire attribute
716 1 ▶ if ( ref $core->{$key} eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if (ref $core->{$key} eq "HASH" and ref $ext->{$key} eq "HASH" and ref $core->{$key}{"select"} eq "ARRAY" and ref $ext->{$key}{"select"} eq "ARRAY") 1 0 1
Condition33%3/9
ref $core->{$key} eq "HASH" and ref $ext->{$key} eq "HASH" and ref $core->{$key}{"select"} eq "ARRAY" and ref $ext->{$key}{"select"} eq "ARRAY"
!ll&&!rl&&r
001
ref $core->{$key} eq "HASH" and ref $ext->{$key} eq "HASH" and ref $core->{$key}{"select"} eq "ARRAY"
!ll&&!rl&&r
001
ref $core->{$key} eq "HASH" and ref $ext->{$key} eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/4
ref $core->{$key} eq "HASH" and ref $ext->{$key} eq "HASH" and ref $core->{$key}{"select"} eq "ARRAY" and ref $ext->{$key}{"select"} eq "ARRAY"
ref $core->{$key} eq "HASH" ref $ext->{$key} eq "HASH" ref $core->{$key}{"select"} eq "ARRAY" ref $ext->{$key}{"select"} eq "ARRAY"
Truth table20%1/5
A and B and C and D
A= ref $core->{$key} eq "HASH"B= ref $ext->{$key} eq "HASH"C= ref $core->{$key}{"select"} eq "ARRAY"D= ref $ext->{$key}{"select"} eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
717 && ref $ext->{$key} eq 'HASH'
718 && ref $core->{$key}{select} eq 'ARRAY'
719 && ref $ext->{$key}{select} eq 'ARRAY' )
720 {
721 my %existing =
722 28 map { $_->{k} => 1 }
723 28 ▶ grep { ref $_ eq 'HASH' && exists $_->{k} }
Condition33%1/3
ref $_ eq 'HASH' && exists $_->{'k'}
!ll&&!rl&&r
0028
MC/DC0%0/2
ref $_ eq 'HASH' && exists $_->{'k'}
ref $_ eq 'HASH' exists $_->{'k'}
Truth table33%1/3
A && B
A= ref $_ eq 'HASH'B= exists $_->{'k'}
ABresult
0X0
100
111
724 1 @{ $core->{$key}{select} };
725 1 for my $opt ( @{ $ext->{$key}{select} } ) {
726 1 ▶ next unless ref $opt eq 'HASH' && $opt->{k};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opt eq "HASH" and $opt->{"k"} 0 1 1
Condition33%1/3
ref $opt eq "HASH" and $opt->{"k"}
!ll&&!rl&&r
001
MC/DC0%0/2
ref $opt eq "HASH" and $opt->{"k"}
ref $opt eq "HASH" $opt->{"k"}
Truth table33%1/3
A and B
A= ref $opt eq "HASH"B= $opt->{"k"}
ABresult
0X0
100
111
727 1 ▶ unless ( $existing{ $opt->{k} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($existing{$opt->{"k"}}) 1 0 1
728 1 push @{ $core->{$key}{select} }, $opt;
729 1 verbose
730 " Appended select option '$opt->{k}' to attribute '$key'\n";
731 }
732 }
733 1 next;
734 }
735  
736 0 warn "Warning [$ext_file]: Overriding existing attribute '$key'\n";
737 }
738 2 $core->{$key} = $ext->{$key};
739 2 verbose " Added attribute: $key\n";
740 }
741 }
742  
743 1 ▶sub merge_tree {
Subroutine merge_tree: called CC=6 SCAR=22.7
744 1 my ( $core_tree, $ext_tree, $ext_file ) = @_;
745  
746 1 my $insert_into = $ext_tree->{insert_into};
747 1 my $nodes = $ext_tree->{nodes};
748  
749 1 ▶ unless ( $insert_into && $nodes ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($insert_into and $nodes) 0 1 1
Condition33%1/3
$insert_into and $nodes
!ll&&!rl&&r
001
MC/DC0%0/2
$insert_into and $nodes
$insert_into $nodes
Truth table33%1/3
A and B
A= $insert_intoB= $nodes
ABresult
0X0
100
111
750 0 warn
751 "Warning [$ext_file]: tree extension requires 'insert_into' and 'nodes'\n";
752 0 return;
753 }
754  
755 # Find the target node by path (e.g., "generalParameters/plugins")
756 1 my @path_parts = split '/', $insert_into;
757 1 my $target = find_tree_node( $core_tree, \@path_parts );
758  
759 1 ▶ unless ($target) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target) 0 1 1
760 0 warn "Warning [$ext_file]: Could not find tree path: $insert_into\n";
761 0 return;
762 }
763  
764 # Insert the new nodes
765 1 my $insert_after = $ext_tree->{insert_after};
766 1 my $insert_before = $ext_tree->{insert_before};
767  
768 1 ▶ if ($insert_after) {
Branch: 2 branches
BranchTrueFalseTotal
if ($insert_after) { } 1 0 1
elsif ($insert_before) { } 0 0 0
769 1 insert_nodes_after( $target->{nodes}, $insert_after, $nodes,
770 $ext_file );
771 }
772 elsif ($insert_before) {
773 0 insert_nodes_before( $target->{nodes}, $insert_before, $nodes,
774 $ext_file );
775 }
776 else {
777 # Default: append at end
778 0 push @{ $target->{nodes} }, @$nodes;
779 }
780  
781 1 verbose " Inserted tree nodes into: $insert_into\n";
782 }
783  
784 4 ▶sub find_tree_node {
Subroutine find_tree_node: called CC=8 SCAR=21.3
785 4 my ( $tree, $path_parts ) = @_;
786  
787 4 ▶ return undef unless @$path_parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @$path_parts 0 4 4
788  
789 4 my $current_name = shift @$path_parts;
790  
791 4 for my $node (@$tree) {
792 12 ▶ next unless ref($node) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node eq "HASH" 1 11 12
793 11 ▶ next unless ( $node->{title} // '' ) eq $current_name;
Branch: 1 branch
BranchTrueFalseTotal
unless ($node->{"title"} // "") eq $current_name 7 4 11
Condition50%1/2
$node->{"title"} // ""
l!l
110
MC/DC0%0/1
$node->{"title"} // ""
$node->{"title"}
Truth table50%1/2
A
A= $node->{"title"}
Aresult
11
00
794  
795 4 ▶ if ( @$path_parts == 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$path_parts == 0) { } 2 2 4
elsif ($node->{'nodes'}) { } 2 0 2
796 2 return $node;
797 }
798 elsif ( $node->{nodes} ) {
799 2 return find_tree_node( $node->{nodes}, $path_parts );
800 }
801 }
802  
803 0 return undef;
804 }
805  
806 2 ▶sub insert_nodes_after {
Subroutine insert_nodes_after: called CC=6 SCAR=18.0
807 2 my ( $nodes_array, $after_title, $new_nodes, $ext_file ) = @_;
808  
809 2 for my $i ( 0 .. $#$nodes_array ) {
810 36 my $node = $nodes_array->[$i];
811 36 ▶ my $title = ref($node) eq 'HASH' ? $node->{title} : $node;
Branch: 1 branch
BranchTrueFalseTotal
ref $node eq 'HASH' ? : 21 15 36
812 36 ▶ next unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 0 36 36
813 36 ▶ if ( $title eq $after_title ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title eq $after_title) 1 35 36
814 1 splice @$nodes_array, $i + 1, 0, @$new_nodes;
815 1 return;
816 }
817 }
818  
819 # Reference not found in the target: append at end rather than failing.
820 1 ▶ warn "Warning"
Branch: 1 branch
BranchTrueFalseTotal
$ext_file ? : 1 0 1
821 . ( $ext_file ? " [$ext_file]" : "" )
822 . ": insert_after reference '$after_title' not found, appending at end\n";
823 1 push @$nodes_array, @$new_nodes;
824 }
825  
826 0 ▶sub insert_nodes_before {
Subroutine insert_nodes_before: not called CC=6 SCAR=37.4
827 0 my ( $nodes_array, $before_title, $new_nodes, $ext_file ) = @_;
828  
829 0 for my $i ( 0 .. $#$nodes_array ) {
830 0 my $node = $nodes_array->[$i];
831 0 ▶ my $title = ref($node) eq 'HASH' ? $node->{title} : $node;
Branch: 1 branch
BranchTrueFalseTotal
ref $node eq 'HASH' ? : 0 0 0
832 0 ▶ next unless defined $title;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $title 0 0 0
833 0 ▶ if ( $title eq $before_title ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title eq $before_title) 0 0 0
834 0 splice @$nodes_array, $i, 0, @$new_nodes;
835 0 return;
836 }
837 }
838  
839 # Reference not found in the target: append at end (consistent with
840 # insert_nodes_after). Prepending at position 0 would reorder
841 # unrelated, unrelated nodes and is almost never what the admin
842 # meant when the sibling is simply missing.
843 0 ▶ warn "Warning"
Branch: 1 branch
BranchTrueFalseTotal
$ext_file ? : 0 0 0
844 . ( $ext_file ? " [$ext_file]" : "" )
845 . ": insert_before reference '$before_title' not found, appending at end\n";
846 0 push @$nodes_array, @$new_nodes;
847 }
848  
849 1 ▶sub merge_ctrees {
Subroutine merge_ctrees: called CC=4 SCAR=13.9
850 1 my ( $core_ctrees, $ext_ctrees, $ext_file ) = @_;
851  
852 1 for my $ctree_name ( keys %$ext_ctrees ) {
853 1 my $spec = $ext_ctrees->{$ctree_name};
854 1 ▶ my @specs = ref $spec eq 'ARRAY' ? @$spec : ($spec);
Branch: 1 branch
BranchTrueFalseTotal
ref $spec eq 'ARRAY' ? : 0 1 1
855 1 for my $s (@specs) {
856 1 apply_ctree_extension( $core_ctrees, $ctree_name, $s, $ext_file );
857 }
858 }
859 }
860  
861 # Apply a single ctree extension - used by both merge_ctrees and the redefined cTrees function
862 1 ▶sub apply_ctree_extension {
Subroutine apply_ctree_extension: called CC=9 SCAR=29.2
863 1 my ( $core_ctrees, $ctree_name, $ext_spec, $ext_file ) = @_;
864  
865 1 ▶ unless ( exists $core_ctrees->{$ctree_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $core_ctrees->{$ctree_name}) 0 1 1
866  
867 # Create new ctree entry
868 0 ▶ $core_ctrees->{$ctree_name} = $ext_spec->{nodes} || [];
Condition0%0/2
$ext_spec->{'nodes'} || []
l!l
00
MC/DC0%0/1
$ext_spec->{'nodes'} || []
$ext_spec->{'nodes'}
Truth table0%0/2
A
A= $ext_spec->{'nodes'}
Aresult
11
00
869 0 verbose " Created new ctree: $ctree_name\n";
870 0 return;
871 }
872  
873 1 my $nodes = $ext_spec->{nodes};
874 1 ▶ unless ($nodes) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nodes) 0 1 1
875 0 warn
876 "Warning [$ext_file]: ctree '$ctree_name' extension requires 'nodes'\n";
877 0 return;
878 }
879  
880 1 my $insert_into = $ext_spec->{insert_into};
881 1 my $insert_after = $ext_spec->{insert_after};
882 1 my $insert_before = $ext_spec->{insert_before};
883  
884 # Determine target array for insertion
885 1 my $target_array;
886 1 ▶ if ($insert_into) {
Branch: 1 branch
BranchTrueFalseTotal
if ($insert_into) { } 1 0 1
887  
888 # Navigate to nested node using path (e.g., "oidcRPMetaDataOptions/oidcRPMetaDataOptionsAdvanced")
889 1 my @path_parts = split '/', $insert_into;
890 my $target =
891 1 find_tree_node( $core_ctrees->{$ctree_name}, \@path_parts );
892 1 ▶ unless ($target) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target) 0 1 1
893 0 warn
894 "Warning [$ext_file]: Could not find ctree path: $ctree_name/$insert_into\n";
895 0 return;
896 }
897 1 $target_array = $target->{nodes};
898 1 ▶ unless ($target_array) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target_array) 0 1 1
899 0 warn
900 "Warning [$ext_file]: Target node '$insert_into' has no 'nodes' array\n";
901 0 return;
902 }
903 }
904 else {
905 0 $target_array = $core_ctrees->{$ctree_name};
906 }
907  
908 1 ▶ if ($insert_after) {
Branch: 2 branches
BranchTrueFalseTotal
if ($insert_after) { } 1 0 1
elsif ($insert_before) { } 0 0 0
909 1 insert_nodes_after( $target_array, $insert_after, $nodes, $ext_file );
910 }
911 elsif ($insert_before) {
912 0 insert_nodes_before( $target_array, $insert_before, $nodes, $ext_file );
913 }
914 else {
915 0 push @$target_array, @$nodes;
916 }
917  
918 1 verbose " Extended ctree: $ctree_name\n";
919 }
920  
921 1 ▶sub merge_constants {
Subroutine merge_constants: called CC=5 SCAR=18.4
922 1 my ( $core, $ext, $ext_file ) = @_;
923  
924 1 for my $key ( keys %$ext ) {
925 1 ▶ if ( exists $core->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $core->{$key}) 0 1 1
926 0 die
927 "Error [$ext_file]: Portal constant '$key' already exists with value $core->{$key}\n";
928 }
929  
930 1 my $value = $ext->{$key};
931 1 ▶ if ( $value >= 0 && $value < 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value >= 0 and $value < 200) 0 1 1
Condition33%1/3
$value >= 0 and $value < 200
!ll&&!rl&&r
010
MC/DC0%0/2
$value >= 0 and $value < 200
$value >= 0 $value < 200
Truth table33%1/3
A and B
A= $value >= 0B= $value < 200
ABresult
0X0
100
111
932 0 warn
933 "Warning [$ext_file]: Plugin constants should use values >= 200 (got $key => $value)\n";
934 }
935  
936 1 $core->{$key} = $value;
937 1 verbose " Added constant: $key => $value\n";
938 }
939 }
940  
941 0 ▶sub update_language_files {
Subroutine update_language_files: not called CC=12 SCAR=50.5
942 0 my ( $dir, $translations ) = @_;
943  
944 # List all language files
945 0 ▶ opendir my $dh, $dir or die "Cannot open language directory $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or die "Cannot open language directory ${dir}: $!" 0 0 0
946 0 my @lang_files = grep { /\.json$/ } readdir $dh;
947 0 closedir $dh;
948  
949 0 my $json =
950 JSON->new->utf8->pretty->canonical->space_before(0)->space_after(0);
951  
952 0 for my $lang_file (@lang_files) {
953 0 my $lang_path = "$dir/$lang_file";
954  
955 # Extract language code from filename (e.g., "fr.json" -> "fr")
956 0 my ($lang_code) = $lang_file =~ /^(.+)\.json$/;
957  
958 # Load existing translations
959 0 my $content;
960 {
961 0 ▶ open my $fh, '<', $lang_path or die "Cannot read $lang_path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $lang_path or die "Cannot read ${lang_path}: $!" 0 0 0
962 0 local $/;
963 0 $content = <$fh>;
964 0 close $fh;
965 }
966 0 my $lang_data = $json->decode($content);
967  
968 # Add new translations
969 0 my $modified = 0;
970 0 for my $key ( keys %$translations ) {
971 0 my $trans = $translations->{$key};
972  
973 # Determine the text to use:
974 # 1. Use the specific language if available
975 # 2. Fall back to English
976 # 3. Fall back to the first available language
977 0 my $text;
978 0 ▶ if ( ref($trans) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $trans eq 'HASH') { } 0 0 0
979 $text = $trans->{$lang_code} // $trans->{en}
980 0 ▶ // ( values %$trans )[0];
Condition0%0/6
($trans->{$lang_code} // $trans->{"en"}) // (values %$trans)[0]
l!l&&r!l&&!r
000
$trans->{$lang_code} // $trans->{"en"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($trans->{$lang_code} // $trans->{"en"}) // (values %$trans)[0]
$trans->{$lang_code} $trans->{"en"} (values %$trans)[0]
Truth table0%0/4
A // B // C
A= $trans->{$lang_code}B= $trans->{"en"}C= (values %$trans)[0]
ABCresult
1XX1
01X1
0011
0000
981 }
982 else {
983 # If trans is a scalar, use it directly (same for all languages)
984 0 $text = $trans;
985 }
986  
987 0 ▶ if ( defined $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 0 0 0
988 0 ▶ if ( exists $lang_data->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lang_data->{$key}) 0 0 0
989 0 verbose " [$lang_code] Overriding existing key '$key'\n";
990 }
991 0 $lang_data->{$key} = $text;
992 0 $modified = 1;
993 }
994 }
995  
996 # Write back if modified
997 0 ▶ if ($modified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified) 0 0 0
998 0 $content = $json->encode($lang_data);
999  
1000 # Compact format like addTrEntry
1001 0 $content =~ s/\n\s+/\n/sg;
1002 0 $content =~ s/\n*$//s;
1003  
1004 0 ▶ open my $fh, '>', $lang_path or die "Cannot write $lang_path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $lang_path or die "Cannot write ${lang_path}: $!" 0 0 0
1005 0 print $fh $content;
1006 0 close $fh;
1007  
1008 0 verbose " Updated $lang_file\n";
1009 }
1010 }
1011 }
1012  
1013 0 ▶sub minify_conftree {
Subroutine minify_conftree: not called CC=12 SCAR=50.5
1014 0 my ($conftree_file) = @_;
1015  
1016 # Get directory and basename for proper source map paths
1017 0 my $dir = dirname($conftree_file);
1018 0 my $basename = basename($conftree_file);
1019 0 my $min_basename = $basename;
1020 0 $min_basename =~ s/\.js$/.min.js/;
1021  
1022 # If source and min are the same (shouldn't happen), skip
1023 0 ▶ if ( $min_basename eq $basename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min_basename eq $basename) 0 0 0
1024 0 warn "Warning: Cannot determine minified filename for $conftree_file\n";
1025 0 return;
1026 }
1027  
1028 0 verbose "Minifying $conftree_file -> $dir/$min_basename\n";
1029  
1030 # Save current directory and change to target directory
1031 0 my $orig_dir = getcwd();
1032 0 ▶ chdir $dir or do {
Branch: 1 branch
BranchTrueFalseTotal
chdir $dir or do { warn "Warning: Cannot chdir to ${dir}: $!\n"; return } 0 0 0
1033 0 warn "Warning: Cannot chdir to $dir: $!\n";
1034 0 return;
1035 };
1036  
1037 0 my $success = 0;
1038  
1039 # Prefer terser
1040 0 my $terser_version = `terser --version 2>/dev/null`;
1041 0 ▶ if ( $? == 0 && $terser_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0 and $terser_version) 0 0 0
Condition0%0/3
$? == 0 and $terser_version
!ll&&!rl&&r
000
MC/DC0%0/2
$? == 0 and $terser_version
$? == 0 $terser_version
Truth table0%0/3
A and B
A= $? == 0B= $terser_version
ABresult
0X0
100
111
1042 0 verbose " Using terser\n";
1043 0 my @cmd = (
1044 'terser', $basename, '--compress', '--mangle',
1045 '--comments', '/Copyr/i', '--source-map', '-o',
1046 $min_basename,
1047 );
1048 0 $success = ( system(@cmd) == 0 );
1049 }
1050  
1051 # Fall back to uglifyjs
1052 0 ▶ if ( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
1053 0 my $uglifyjs_version = `uglifyjs --version 2>/dev/null`;
1054 0 ▶ if ( $? == 0 && $uglifyjs_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? == 0 and $uglifyjs_version) 0 0 0
Condition0%0/3
$? == 0 and $uglifyjs_version
!ll&&!rl&&r
000
MC/DC0%0/2
$? == 0 and $uglifyjs_version
$? == 0 $uglifyjs_version
Truth table0%0/3
A and B
A= $? == 0B= $uglifyjs_version
ABresult
0X0
100
111
1055 0 my ($major) = $uglifyjs_version =~ /^[^\d]*(\d)/;
1056 0 ▶ $major //= 3;
Condition0%0/2
$major //= 3
l!l
00
MC/DC0%0/1
$major //= 3
$major
Truth table0%0/2
A
A= $major
Aresult
11
00
1057  
1058 0 my @cmd;
1059 0 ▶ if ( $major == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($major == 2) { } 0 0 0
1060 0 @cmd = (
1061 'uglifyjs', $basename,
1062 '--compress', '--mangle',
1063 '--comments', '/Copyr/i',
1064 '--source-map', "$min_basename.map",
1065 '-o', $min_basename,
1066 );
1067 }
1068 else {
1069 0 @cmd = (
1070 'uglifyjs', $basename, '--compress', '--mangle',
1071 '--comments', '/Copyr/i', '--source-map', '-o',
1072 $min_basename,
1073 );
1074 }
1075  
1076 0 verbose " Using uglifyjs (version $major)\n";
1077 0 $success = ( system(@cmd) == 0 );
1078 }
1079 }
1080  
1081 # No minifier available or all failed, just copy
1082 0 ▶ if ( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
1083 0 verbose " No minifier available, copying file\n";
1084 0 copy_file( $basename, $min_basename );
1085 }
1086  
1087 # Restore original directory
1088 0 ▶ chdir $orig_dir or warn "Warning: Cannot chdir back to $orig_dir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
chdir $orig_dir or warn "Warning: Cannot chdir back to ${orig_dir}: $!\n" 0 0 0
1089 }
1090  
1091 0 ▶sub copy_file {
Subroutine copy_file: not called CC=4 SCAR=30.0
1092 0 my ( $src, $dst ) = @_;
1093 0 ▶ open my $in, '<', $src or die "Cannot open $src: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $src or die "Cannot open ${src}: $!" 0 0 0
1094 0 ▶ open my $out, '>', $dst or die "Cannot open $dst: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $dst or die "Cannot open ${dst}: $!" 0 0 0
1095 0 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 0 0 0
1096 0 print $out $_;
1097 }
1098 0 close $in;
1099 0 close $out;
1100 }
1101  
1102 __END__
« blib/lib/Lemonldap/NG/Manager/Cli.pm ↑ Summary blib/lib/Lemonldap/NG/Manager/Conf/Diff.pm »