line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use strict; |
12
|
59
|
|
|
59
|
|
364
|
use warnings; |
|
59
|
|
|
|
|
117
|
|
|
59
|
|
|
|
|
1499
|
|
13
|
59
|
|
|
59
|
|
287
|
use Exporter; |
|
59
|
|
|
|
|
148
|
|
|
59
|
|
|
|
|
1336
|
|
14
|
59
|
|
|
59
|
|
300
|
|
|
59
|
|
|
|
|
133
|
|
|
59
|
|
|
|
|
1859
|
|
15
|
|
|
|
|
|
|
use vars qw/@EXPORT/; |
16
|
59
|
|
|
59
|
|
279
|
|
|
59
|
|
|
|
|
117
|
|
|
59
|
|
|
|
|
39250
|
|
17
|
|
|
|
|
|
|
@EXPORT = qw(applications models); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $test = shift || 0; |
20
|
|
|
|
|
|
|
|
21
|
59
|
|
100
|
59
|
0
|
26500
|
my ( %categories, %appli_info, %applications ); |
22
|
|
|
|
|
|
|
my %done_cat; |
23
|
59
|
|
|
|
|
155
|
my @dir_to_scan = $test ? qw/lib/ : @INC; |
24
|
59
|
|
|
|
|
0
|
|
25
|
59
|
100
|
|
|
|
354
|
foreach my $dir ( map { glob("$_/Config/Model/*.d") } @dir_to_scan ) { |
26
|
|
|
|
|
|
|
my ($cat) = ( $dir =~ m!.*/([\w\-]+)\.d! ); |
27
|
59
|
|
|
|
|
135
|
|
|
495
|
|
|
|
|
15651
|
|
28
|
222
|
|
|
|
|
1308
|
if ( $cat !~ /^user|system|application$/ ) { |
29
|
|
|
|
|
|
|
warn "available_models: skipping unexpected category: $cat\n"; |
30
|
222
|
50
|
|
|
|
999
|
next; |
31
|
0
|
|
|
|
|
0
|
} |
32
|
0
|
|
|
|
|
0
|
|
33
|
|
|
|
|
|
|
foreach my $file ( sort glob("$dir/*") ) { |
34
|
|
|
|
|
|
|
next if $file =~ m!/README!; |
35
|
222
|
|
|
|
|
11395
|
next if $file =~ /(~|\.bak|\.orig)$/; |
36
|
333
|
50
|
|
|
|
1170
|
my ($appli) = ( $file =~ m!.*/([\w\-]+)! ); |
37
|
333
|
50
|
|
|
|
1099
|
|
38
|
333
|
|
|
|
|
1344
|
# ensure that an appli file of a cat is not parsed twice |
39
|
|
|
|
|
|
|
# (useful in dev, where system appli file may clobber |
40
|
|
|
|
|
|
|
# appli file in dvelopment |
41
|
|
|
|
|
|
|
next if $done_cat{$cat}{$appli}; |
42
|
|
|
|
|
|
|
|
43
|
333
|
100
|
|
|
|
1062
|
$appli_info{$appli}{_file} = $file; |
44
|
|
|
|
|
|
|
$appli_info{$appli}{_category} = $cat; |
45
|
177
|
|
|
|
|
504
|
open my $fh, '<', $file || die "Can't open file $file:$!"; |
46
|
177
|
|
|
|
|
319
|
while (<$fh>) { |
47
|
177
|
|
50
|
|
|
5353
|
chomp; |
48
|
177
|
|
|
|
|
2371
|
s/^\s+//; |
49
|
236
|
|
|
|
|
503
|
s/\s+$//; |
50
|
236
|
|
|
|
|
757
|
s/#.*//; |
51
|
236
|
|
|
|
|
595
|
my ( $k, $v ) = split /\s*=\s*/; |
52
|
236
|
|
|
|
|
346
|
next unless $v; |
53
|
236
|
|
|
|
|
1155
|
if ( $k =~ /model/i ) { |
54
|
236
|
50
|
|
|
|
522
|
push @{ $categories{$cat} }, $appli unless $done_cat{$cat}{$appli}; |
55
|
236
|
100
|
|
|
|
706
|
$done_cat{$cat}{$appli} = 1; |
56
|
177
|
50
|
|
|
|
475
|
} |
|
177
|
|
|
|
|
530
|
|
57
|
177
|
|
|
|
|
383
|
|
58
|
|
|
|
|
|
|
$appli_info{$appli}{$k} = $v; |
59
|
|
|
|
|
|
|
$applications{$appli} = $v if $k =~ /model/i; |
60
|
236
|
|
|
|
|
563
|
} |
61
|
236
|
100
|
|
|
|
2076
|
die "Missing model line in file $file\n" unless $done_cat{$cat}{$appli}; |
62
|
|
|
|
|
|
|
} |
63
|
177
|
50
|
|
|
|
2211
|
} |
64
|
|
|
|
|
|
|
return \%categories, \%appli_info, \%applications; |
65
|
|
|
|
|
|
|
} |
66
|
59
|
|
|
|
|
477
|
|
67
|
|
|
|
|
|
|
my @i = available_models(@_); |
68
|
|
|
|
|
|
|
return join( ' ', sort values %{ $i[2] } ) . "\n"; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
0
|
0
|
|
|
71
|
0
|
|
|
|
|
|
my @i = available_models(@_); |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return join( ' ', sort keys %{ $i[2] } ) . "\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
0
|
|
1; |
76
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# ABSTRACT: List available models and applications |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=pod |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=encoding UTF-8 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Config::Model::Lister - List available models and applications |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 VERSION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
version 2.152 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SYNOPSIS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
perl -MConfig::Model::Lister -e'print Config::Model::Lister::models;' |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
perl -MConfig::Model::Lister -e'print Config::Model::Lister::applications;' |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Small modules to list available models or applications whose config |
101
|
|
|
|
|
|
|
can be edited by L<cme>. This module is designed to be used by bash |
102
|
|
|
|
|
|
|
completion. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
All functions accept an optional boolean parameter. When true, only |
105
|
|
|
|
|
|
|
the local C<lib> dir is scanned. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 FUNCTIONS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 available_models |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns an array of 3 hash refs: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
category (system or user or application) => application list. E.g. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
{ system => [ 'popcon' , 'fstab'] } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
application name to model information. E.g. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
{ 'multistrap' => { model => 'Multistrap', require_config_file => 1 } |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
application name to model name. E.g. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
{ popcon => 'Popcon', 'multistrap' => 'Multistrap' } |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 models |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns a string with the list of models. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 applications |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Returns a string with the list of editable applications. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Dominique Dumont |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This software is Copyright (c) 2005-2022 by Dominique Dumont. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This is free software, licensed under: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The GNU Lesser General Public License, Version 2.1, February 1999 |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |