blib/lib/Config/Model/Lister.pm

filter: Statementstmt 85.7% 60 / 70 Branchbran 63.6% 14 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 4 totaltotal 76.5% 85 / 111 CC 18 SCAR 19.2
CC
18
Cov
80%
available_models
11.7
process_app_data
6.1
models
6.0
CRAP 6.8
« blib/lib/Config/Model/Describe.pm ↑ Summary blib/lib/Config/Model/IdElementReference.pm »
1 #
2 # This file is part of Config-Model
3 #
4 # This software is Copyright (c) 2005-2022 by Dominique Dumont.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package Config::Model::Lister 2.169;
11  
12 59 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 59 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 59 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 59 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 ## no critic (Modules::ProhibitAutomaticExportation)
18 59 ▶use vars qw/@EXPORT/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 59 ▶use feature qw/postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 59 ▶no warnings qw/experimental::postderef experimental::signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 59 @EXPORT = qw(applications models);
24  
25 54 ▶sub available_models ($test = 0) {
Subroutine available_models: called CC=11 SCAR=24.6
Pod undocumented
26 54 my ( %categories, %appli_info, %applications );
27 54 my %done_cat;
28 54 ▶ my @dir_to_scan = $test ? qw/lib/ : @INC;
Branch: 1 branch
BranchTrueFalseTotal
$test ? : 12 42 54
29  
30 58 ▶ foreach my $dir ( map { glob("$_/Config/Model/*.d") } @dir_to_scan ) {
Subroutine BEGIN: called CC=1 SCAR=0.0
31 102 my ($cat) = ( $dir =~ m!.*/([\w\-]+)\.d! );
32  
33 102 ▶ if ( $cat !~ /^user|system|application$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cat =~ /^user|system|application$/u) 0 102 102
34 0 warn "available_models: skipping unexpected category: $cat\n";
35 0 next;
36 }
37  
38 102 foreach my $file ( sort glob("$dir/*") ) {
39 204 ▶ next if $file =~ m!/README!;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[/README]u 0 204 204
40 204 ▶ next if $file =~ /(~|\.bak|\.orig)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /(~|\.bak|\.orig)$/u 0 204 204
41 204 my ($appli) = ( $file =~ m!.*/([\w\-]+)! );
42  
43 # ensure that an appli file of a cat is not parsed twice
44 # (useful in dev, where system appli file may clobber
45 # appli file in development
46 204 ▶ next if $done_cat{$cat}{$appli};
Branch: 1 branch
BranchTrueFalseTotal
if $done_cat{$cat}{$appli} 96 108 204
47  
48 108 $appli_info{$appli}{_file} = $file;
49 108 $appli_info{$appli}{_category} = $cat;
50 108 ▶ open my $fh, '<', $file || die "Can't open file $file:$!";
Condition50%1/2
$file || die("Can't open file ${file}:$!")
l!l
1080
MC/DC0%0/1
$file || die("Can't open file ${file}:$!")
$file
Truth table50%1/2
A
A= $file
Aresult
11
00
51 108 process_app_data($appli, $fh, \%categories, \%done_cat, \%appli_info, \%applications);
52 108 close $fh;
53 108 ▶ die "Missing model line in file $file\n" unless $done_cat{$cat}{$appli};
Branch: 1 branch
BranchTrueFalseTotal
unless $done_cat{$cat}{$appli} 0 108 108
54 }
55 }
56 54 return \%categories, \%appli_info, \%applications;
57 }
58  
59 108 ▶sub process_app_data($appli, $fh, $categories, $done_cat, $appli_info, $applications) {
Subroutine process_app_data: called CC=6 SCAR=18.2
Pod undocumented
60 108 my $cat = $appli_info->{$appli}{_category};
61 108 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 108 108 216
62 108 chomp($line);
63 108 $line =~ s/^\s+//;
64 108 $line =~ s/\s+$//;
65 108 $line =~ s/#.*//;
66 108 my ( $k, $v ) = split /\s*=\s*/, $line;
67 108 ▶ next unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 108 108
68 108 ▶ if ( $k =~ /model/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /model/iu) 108 0 108
69 108 ▶ push @{ $categories->{$cat} }, $appli unless $done_cat->{$cat}{$appli};
Branch: 1 branch
BranchTrueFalseTotal
unless $done_cat->{$cat}{$appli} 108 0 108
70 108 $done_cat->{$cat}{$appli} = 1;
71 }
72  
73 108 $appli_info->{$appli}{$k} = $v;
74 108 ▶ $applications->{$appli} = $v if $k =~ /model/i;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /model/iu 108 0 108
75 }
76 108 return;
77 }
78  
79 0 ▶sub models ($test = 0) {
Subroutine models: not called CC=2 SCAR=17.9
Pod undocumented
80 0 my @i = available_models($test);
81 0 return join( ' ', sort values %{ $i[2] } ) . "\n";
82 }
83  
84 0 ▶sub applications ($test = 0) {
Subroutine applications: not called CC=2 SCAR=17.9
Pod undocumented
85 0 my @i = available_models($test);
86 0 return join( ' ', sort keys %{ $i[2] } ) . "\n";
87 }
88  
89 59 1;
90  
91 # ABSTRACT: List available models and applications
92  
93 __END__
« blib/lib/Config/Model/Describe.pm ↑ Summary blib/lib/Config/Model/IdElementReference.pm »