blib/lib/Config/Model/Itself.pm

filter: Statementstmt 93.3% 438 / 469 Branchbran 68.7% 88 / 128 Conditioncond 63.7% 58 / 91 MC/DCmcdc 28.5% 14 / 49 Subroutinesub 92.7% 51 / 55 Podpod 22.2% 6 / 27 totaltotal 79.9% 655 / 819 CC 135 SCAR 19.3
CC
135
Cov
85%
read_all
15.4
read_app_files
13.1
list_one_class_element
12.0
CRAP 6.9
« blib/lib/Config/Model/Itself/TkEditUI.pm ↑ Summary blib/lib/Config/Model/Itself/BackendDetector.pm »
1 #
2 # This file is part of Config-Model-Itself
3 #
4 # This software is Copyright (c) 2007-2026 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::Itself 2.033;
11  
12 11 ▶use Mouse ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 11 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use feature qw/postderef signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶no warnings qw/experimental::postderef experimental::signatures/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 11 ▶use Config::Model 2.169;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use IO::File ;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use Log::Log4perl 1.11;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use Data::Dumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶use Data::Compare ;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use Path::Tiny 0.125; # for mkdir
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 11 my $logger = Log::Log4perl::get_logger("Backend::Itself");
31  
32 26 ▶subtype 'ModelPathTiny' => as 'Object' => where { $_->isa('Path::Tiny') };
Subroutine __ANON__: called CC=1 SCAR=0.0
33  
34 7 ▶coerce 'ModelPathTiny' => from 'Str' => via {path($_)} ;
Subroutine __ANON__: called CC=1 SCAR=0.0
35  
36 # find all .pl file in model_dir and load them...
37  
38 11 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
39 11 my $orig = shift;
40 11 my $class = shift;
41 11 my %args = @_;
42  
43 11 my $legacy = delete $args{model_object};
44 11 ▶ if ($legacy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($legacy) 11 0 11
45 11 $args{config_model} = $legacy->instance->config_model;
46 11 $args{meta_instance} = $legacy->instance;
47 11 $args{meta_root} = $legacy;
48 }
49 11 return $class->$orig( %args );
50 11 };
51  
52 11 has 'config_model' => (
53 is => 'ro',
54 isa => 'Config::Model',
55 lazy_build => 1,
56 ) ;
57  
58  
59 0 ▶sub _build_config_model {
Subroutine _build_config_model: not called CC=3 SCAR=24.8
60 0 my $self = shift;
61 # don't trigger builders below
62 0 ▶ if ($self->{meta_root}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'meta_root'}) { } 0 0 0
elsif ($self->{'meta_instance'}) { } 0 0 0
63 0 return $self->meta_root->instance->config_model;
64 }
65 elsif ($self->{meta_instance}) {
66 0 return $self->meta_instance->config_model;
67 }
68 else {
69 0 return Config::Model -> new ( ) ;
70 }
71 }
72  
73 11 has check => (is =>'ro', isa => 'Bool', default => 1) ;
74  
75 11 has 'meta_instance' => (
76 is =>'ro',
77 isa =>'Config::Model::Instance',
78 lazy_build => 1,
79 ) ;
80  
81 0 ▶sub _build_meta_instance {
Subroutine _build_meta_instance: not called CC=2 SCAR=17.9
82 0 my $self = shift;
83  
84 # don't trigger builders below
85 0 ▶ if ($self->{meta_root}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'meta_root'}) { } 0 0 0
86 0 return $self->meta_root->instance;
87 }
88 else {
89 # load Config::Model model
90 0 return $self->config_model->instance (
91 root_class_name => 'Itself::Model' ,
92 instance_name => 'meta_model' ,
93 check => $self->check,
94 );
95 }
96  
97 }
98  
99 11 has meta_root => (
100 is =>'ro',
101 isa =>'Config::Model::Node',
102 lazy_build => 1,
103 ) ;
104  
105 0 ▶sub _build_meta_root {
Subroutine _build_meta_root: not called CC=1 SCAR=6.9
106 0 my $self = shift;
107  
108 0 return $self->meta_instance -> config_root ;
109 }
110  
111 11 has cm_lib_dir => (
112 is =>'ro',
113 isa => 'ModelPathTiny',
114 lazy_build => 1,
115 coerce => 1
116 ) ;
117  
118 0 ▶sub _build_cm_lib_dir {
Subroutine _build_cm_lib_dir: not called CC=2 SCAR=17.9
119 0 my $self = shift;
120 0 my $p = path('lib/Config/Model');
121 0 ▶ if (! $p->is_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p->is_dir) 0 0 0
122 0 $p->mkdir();
123 }
124 0 return $p;
125 }
126  
127 11 has force_write => (is =>'ro', isa => 'Bool', default => 0) ;
128 11 has root_model => (is =>'ro', isa => 'str');
129  
130 has modified_classes => (
131 is =>'rw',
132 isa =>'HashRef[Bool]',
133 traits => ['Hash'],
134 11 ▶ default => sub { {} } ,
Subroutine __ANON__: called CC=1 SCAR=0.0
135 11 handles => {
136 clear_classes => 'clear',
137 set_class => 'set',
138 class_was_changed => 'get' ,
139 class_known => 'exists',
140 }
141 ) ;
142  
143 11 has model_dir => (
144 is => 'ro',
145 isa => 'ModelPathTiny',
146 lazy_build => 1,
147 );
148  
149 11 ▶sub _build_model_dir {
Subroutine _build_model_dir: called CC=1 SCAR=0.0
150 11 my $self = shift;
151 11 my $md = $self->cm_lib_dir->child('models');
152 11 $md->mkdir;
153 11 return $md;
154 }
155  
156 11 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
157 11 my $self = shift;
158  
159 # avoid memory cycle
160 11 weaken($self);
161  
162 5205 ▶ my $cb = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
163 5205 my %args = @_ ;
164 5205 ▶ my $p = $args{path} || '' ;
Condition50%1/2
$args{'path'} || ''
l!l
52050
MC/DC0%0/1
$args{'path'} || ''
$args{'path'}
Truth table50%1/2
A
A= $args{'path'}
Aresult
11
00
165 5205 ▶ return unless $p =~ /^class/ ;
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ /^class/u 13 5192 5205
166 5192 ▶ return unless $args{index}; # may be empty when class order is changed
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"index"} 1 5191 5192
167 5191 ▶ return if $self->class_was_changed($args{index}) ;
Branch: 1 branch
BranchTrueFalseTotal
if $self->class_was_changed($args{"index"}) 4228 963 5191
168 963 $logger->info("class $args{index} was modified");
169  
170 963 $self->add_modified_class($args{index}) ;
171 11 } ;
172 11 $self->meta_instance -> on_change_cb($cb) ;
173  
174 11 return;
175 }
176  
177 167 ▶sub add_tracked_class {
Subroutine add_tracked_class: called CC=1 SCAR=0.0
Pod undocumented
178 167 my $self = shift;
179 167 $self->set_class(shift,0) ;
180 167 return;
181 }
182  
183 1130 ▶sub add_modified_class {
Subroutine add_modified_class: called CC=1 SCAR=0.0
Pod undocumented
184 1130 my $self = shift;
185 1130 $self->set_class(shift,1) ;
186 1130 return;
187 }
188  
189 87 ▶sub class_needs_write {
Subroutine class_needs_write: called CC=3 SCAR=11.0
Pod undocumented
190 87 my $self = shift;
191 87 my $name = shift;
192 87 ▶ return ($self->force_write or not $self->class_known($name) or $self->class_was_changed($name)) ;
Condition83%5/6
$self->force_write || !$self->class_known($name) || $self->class_was_changed($name)
l!l&&r!l&&!r
25620
$self->force_write or not $self->class_known($name)
l!l&&r!l&&!r
24162
MC/DC0%0/3
$self->force_write || !$self->class_known($name) || $self->class_was_changed($name)
$self->force_write not $self->class_known($name) $self->class_was_changed($name)
Truth table75%3/4
A or not(B) || C
A= $self->force_writeB= not $self->class_known($name)C= $self->class_was_changed($name)
ABCresult
1XX1
01X1
0011
0000
193 }
194  
195 9 ▶sub read_app_files {
Subroutine read_app_files: called CC=12 SCAR=25.7
Pod undocumented
196 9 my $self = shift;
197 9 ▶ my $force_load = shift || 0;
Condition100%2/2
shift() || 0
l!l
27
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
198 9 my $read_from = shift ;
199 9 my $application = shift ;
200  
201 9 ▶ my $app_dir = $read_from || $self->model_dir->parent;
Condition33%1/3
$read_from || $self->model_dir->parent
l!l&&r!l&&!r
090
MC/DC0%0/2
$read_from || $self->model_dir->parent
$read_from $self->model_dir->parent
Truth table33%1/3
A || B
A= $read_fromB= $self->model_dir->parent
ABresult
1X1
011
000
202 9 my %apps;
203 my %map;
204 9 $logger->info("reading app files from ".$app_dir);
205 9 foreach my $dir ( $app_dir->children(qr/\.d$/) ) {
206  
207 4 $logger->info("reading app dir ".$dir);
208 4 foreach my $file ( $dir->children() ) {
209 8 ▶ next if $file =~ m!/README!;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[/README]u 0 8 8
210 8 ▶ next if $file =~ /(~|\.bak|\.orig)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /(~|\.bak|\.orig)$/u 0 8 8
211 8 ▶ next if $application and $file->basename ne $application;
Branch: 1 branch
BranchTrueFalseTotal
if $application and $file->basename ne $application 0 8 8
Condition33%1/3
$application and $file->basename ne $application
!ll&&!rl&&r
800
MC/DC0%0/2
$application and $file->basename ne $application
$application $file->basename ne $application
Truth table33%1/3
A and B
A= $applicationB= $file->basename ne $application
ABresult
0X0
100
111
212  
213 # bad categories are filtered by the model
214 8 my %data = ( category => $dir->basename('.d') );
215 8 $logger->info("reading app file ".$file);
216  
217 8 foreach ($file->lines({ chomp => 1})) {
218 16 s/^\s+//;
219 16 s/\s+$//;
220 16 s/#.*//;
221 16 my ( $k, $v ) = split /\s*=\s*/;
222 16 ▶ next unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 0 16 16
223 16 $data{$k} = $v;
224 }
225  
226 8 my $appli = $file->basename;
227 8 $apps{$appli} = $data{model} ;
228 8 $map{$appli} = $file;
229  
230 8 ▶ $self->meta_root->load_data(
Branch: 1 branch
BranchTrueFalseTotal
$force_load ? : 0 8 8
231 data => { application => { $appli => \%data } },
232 check => $force_load ? 'no' : 'yes'
233 ) ;
234 }
235 }
236  
237 9 $self->{app_map} = \%map;
238  
239 9 return \%apps;
240 }
241  
242 9 ▶sub read_all ($self, %args) {
Subroutine read_all: called CC=12 SCAR=27.4
Pod undocumented
243 9 ▶ my $force_load = delete $args{force_load} || 0 ;
Condition100%2/2
delete $args{'force_load'} || 0
l!l
27
MC/DC100%1/1
delete $args{'force_load'} || 0
delete $args{'force_load'}
Truth table100%2/2
A
A= delete $args{'force_load'}
Aresult
11
00
244 9 my $read_from ;
245 my $model_dir ;
246 9 ▶ if ($args{read_from}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"read_from"}) 0 9 9
247 0 $read_from = path (delete $args{read_from});
248 0 ▶ die "Cannot read from unknown dir ".$read_from unless $read_from->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $read_from->is_dir 0 0 0
249 0 $model_dir = $read_from->child('models');
250 0 ▶ die "Cannot read from unknown dir ".$model_dir unless $model_dir->is_dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $model_dir->is_dir 0 0 0
251 }
252  
253 9 my $apps = $self-> read_app_files($force_load, $read_from, delete $args{application});
254  
255 9 ▶ my $root_model_arg = delete $args{root_model} || '';
Condition50%1/2
delete $args{'root_model'} || ''
l!l
90
MC/DC0%0/1
delete $args{'root_model'} || ''
delete $args{'root_model'}
Truth table50%1/2
A
A= delete $args{'root_model'}
Aresult
11
00
256 9 ▶ my $model = $apps->{$root_model_arg} || $root_model_arg ;
Condition33%1/3
$apps->{$root_model_arg} || $root_model_arg
l!l&&r!l&&!r
090
MC/DC0%0/2
$apps->{$root_model_arg} || $root_model_arg
$apps->{$root_model_arg} $root_model_arg
Truth table33%1/3
A || B
A= $apps->{$root_model_arg}B= $root_model_arg
ABresult
1X1
011
000
257 9 my $legacy = delete $args{legacy} ;
258  
259 9 ▶ croak "read_all: unexpected parameters ",join(' ', keys %args) if %args ;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 9 9
260  
261 9 my $dir = $self->model_dir;
262 9 $dir->mkdir ;
263  
264 9 my $root_model_file = $model ;
265 9 $root_model_file =~ s!::!/!g ;
266 9 ▶ my $read_dir = $model_dir || $dir;
Condition33%1/3
$model_dir || $dir
l!l&&r!l&&!r
090
MC/DC0%0/2
$model_dir || $dir
$model_dir $dir
Truth table33%1/3
A || B
A= $model_dirB= $dir
ABresult
1X1
011
000
267 9 $logger->info("searching model files in ".$read_dir);
268  
269 9 my @files ;
270 152 ▶ my $wanted = sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
271 152 ▶ push @files, $_ if ( $_->is_file and /\.pl$/
Branch: 1 branch
BranchTrueFalseTotal
if $_->is_file and /\.pl$/u and m[$read_dir/$root_model_file\b]u and not m[\.d/]u 83 69 152
Condition77%7/9
$_->is_file and /\.pl$/u and m[$read_dir/$root_model_file\b]u and not m[\.d/]u
!ll&&!rl&&r
69083
$_->is_file and /\.pl$/u and m[$read_dir/$root_model_file\b]u
!ll&&!rl&&r
69083
$_->is_file and /\.pl$/u
!ll&&!rl&&r
175283
MC/DC50%2/4
$_->is_file and /\.pl$/u and m[$read_dir/$root_model_file\b]u and not m[\.d/]u
$_->is_file /\.pl$/u m[$read_dir/$root_model_file\b]u not m[\.d/]u
Truth table60%3/5
A and B and C and not(D)
A= $_->is_fileB= /\.pl$/uC= m[$read_dir/$root_model_file\b]uD= not m[\.d/]u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
272 and m!$read_dir/$root_model_file\b!
273 and not m!\.d/!
274 ) ;
275 9 } ;
276 9 $read_dir->visit($wanted, { recurse => 1} ) ;
277  
278 9 my %read_models ;
279 my %class_file_map ;
280  
281 9 my @all_models = $self->load_model_files(
282 $read_dir, \@files, $legacy, \%class_file_map, \%read_models
283 );
284  
285 9 ▶ $self->{root_model} = $model || (sort @all_models)[0];
Condition33%1/3
$model || (sort @all_models)[0]
l!l&&r!l&&!r
900
MC/DC0%0/2
$model || (sort @all_models)[0]
$model (sort @all_models)[0]
Truth table33%1/3
A || B
A= $modelB= (sort @all_models)[0]
ABresult
1X1
011
000
286  
287 # Create all classes listed in %read_models to avoid problems with
288 # include statement while calling load_data
289 9 my $root_obj = $self->meta_root ;
290 9 my $class_element = $root_obj->fetch_element('class') ;
291 9 foreach my $class (sort keys %read_models) {
292 167 $class_element->fetch_with_id($class);
293 }
294  
295 #require Tk::ObjScanner; Tk::ObjScanner::scan_object(\%read_models) ;
296  
297 9 $logger->info("loading all extracted data in Config::Model::Itself");
298 # load with a array ref to avoid warnings about missing order
299 9 ▶ $root_obj->load_data(
Branch: 1 branch
BranchTrueFalseTotal
$force_load ? : 2 7 9
300 data => {class => [ %read_models ] },
301 check => $force_load ? 'no' : 'yes'
302 ) ;
303  
304 9 return $self->{map} = \%class_file_map ;
305 }
306  
307 9 ▶sub load_model_files {
Subroutine load_model_files: called CC=5 SCAR=16.1
Pod undocumented
308 9 my ($self, $read_dir, $files, $legacy, $class_file_map, $read_models) = @_;
309  
310 9 my @all_models;
311 9 for my $file (@$files) {
312 83 $logger->info("loading config file $file");
313  
314 # now apply some translation to read model
315 # - translate legacy warp parameters
316 # - expand elements name
317 83 ▶ my @legacy = $legacy ? ( legacy => $legacy ) : () ;
Branch: 1 branch
BranchTrueFalseTotal
$legacy ? : 16 67 83
318 83 my $tmp_model = Config::Model -> new( skip_include => 1, @legacy ) ;
319  
320 # @models order is important to write configuration class back in the same
321 # order as the declaration
322 83 my @models = $tmp_model -> load ( 'Tmp' , $file->absolute ) ;
323 83 push @all_models, @models;
324  
325 83 my $rel_file = $file ;
326 83 $rel_file =~ s/^$read_dir\/?//;
327 83 ▶ die "wrong reg_exp" if $file eq $rel_file ;
Branch: 1 branch
BranchTrueFalseTotal
if $file eq $rel_file 0 83 83
328 83 $class_file_map->{$rel_file} = \@models ;
329  
330 # - move experience, description and level status into parameter info.
331 83 foreach my $model_name (@models) {
332 167 $read_models->{$model_name} = $self->normalize_model($model_name, $tmp_model);
333 }
334 }
335 9 return @all_models;
336 }
337  
338 167 ▶sub normalize_model {
Subroutine normalize_model: called CC=7 SCAR=20.1
Pod undocumented
339 167 my ($self, $model_name, $tmp_model) = @_;
340  
341 # no need to dclone model as Config::Model object is temporary
342 167 my $raw_model = $tmp_model -> get_raw_model( $model_name ) ;
343 167 my $new_model = $tmp_model -> get_model_clone( $model_name ) ;
344  
345 # track read class to identify later classes added by user
346 167 $self->add_tracked_class($model_name);
347  
348 # some modifications may be done to cope with older model styles. If a modif
349 # was done, mark the class as changed so it will be saved later
350 167 ▶ $self->add_modified_class($model_name) unless Compare($raw_model, $new_model) ;
Branch: 1 branch
BranchTrueFalseTotal
unless Compare($raw_model, $new_model) 167 0 167
351  
352 # translate legacy and copy packed status, level, etc inside element hash
353 167 $tmp_model->copy_element_properties($new_model, $raw_model, $model_name);
354  
355 # Since accept specs and elements are stored in a ordered hash,
356 # load_data expects a array ref instead of a hash ref.
357 # Build this array ref taking the order into
358 # account
359 167 foreach my $what (qw/element accept/) {
360 334 my $list = delete $new_model -> {$what.'_list'} ;
361 334 my $h = delete $new_model -> {$what} ;
362 334 $new_model -> {$what} = [] ;
363 334 foreach my $name (@$list) {
364 1062 push @{$new_model->{$what}}, $name, $h->{$name}
365 }
366 ;
367 }
368  
369 # remove hash key with undefined values
370 167 foreach my $name (keys %$new_model) {
371 482 ▶ if (not defined $new_model->{$name} or $new_model->{$name} eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $new_model->{$name} or $new_model->{$name} eq "") 0 482 482
Condition33%1/3
not defined $new_model->{$name} or $new_model->{$name} eq ""
l!l&&r!l&&!r
00482
MC/DC0%0/2
not defined $new_model->{$name} or $new_model->{$name} eq ""
not defined $new_model->{$name} $new_model->{$name} eq ""
Truth table33%1/3
not(A) or B
A= not defined $new_model->{$name}B= $new_model->{$name} eq ""
ABresult
1X1
011
000
372 0 delete $new_model->{$name};
373 }
374 }
375 167 return $new_model ;
376 }
377  
378 # internal
379 88 ▶sub get_perl_data_model ($self, $class_name, $factorize = 'all') {
Subroutine get_perl_data_model: called CC=4 SCAR=13.9
Pod undocumented
380 88 my $root_obj = $self->{meta_root};
381  
382 88 my $class_element = $root_obj->fetch_element('class') ;
383  
384 # skip if class was deleted during edition
385 88 ▶ return unless $class_element->defined($class_name) ;
Branch: 1 branch
BranchTrueFalseTotal
unless $class_element->defined($class_name) 1 87 88
386  
387 87 my $class_elt = $class_element -> fetch_with_id($class_name) ;
388  
389 87 my $model = $class_elt->dump_as_data ;
390  
391 # now apply some translation to read model
392 # - Do NOT translate legacy warp parameters
393 # - Do not compact elements name
394  
395 87 factorize_model($model, $factorize);
396  
397 # don't forget to add name
398 87 ▶ $model->{name} = $class_name if keys %$model;
Branch: 1 branch
BranchTrueFalseTotal
if keys %$model 87 0 87
399  
400 87 return $model ;
401 }
402  
403 # depending on property, the factorization method is different
404 11 my %may_factorize = (
405 description => \&factorize_with_alias,
406 level => \&factorize_reverse_packed,
407 status => \&factorize_reverse_packed,
408 summary => \&factorize_with_alias,
409 warp => \&factorize_with_alias,
410 );
411  
412 # move some element data out of element structure, and reduce
413 # redundancies
414 90 ▶sub factorize_model ($model, $factorize = 'none') {
Subroutine factorize_model: called CC=3 SCAR=11.0
Pod undocumented
415 90 my $to_factorize = get_properties_to_factorize($factorize);
416  
417 90 move_properties_out_of_element($model, $to_factorize);
418  
419 90 $model->{element} = factorize_element($model->{element});
420  
421 # compare elements data and remove duplicated data
422 90 ▶ while (my ($prop, $sub) = each $to_factorize->%*) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$to_factorize) 445 90 535
423 445 $sub->($model->{$prop});
424 }
425 }
426  
427 90 ▶sub get_properties_to_factorize($factorize) {
Subroutine get_properties_to_factorize: called CC=5 SCAR=21.7
Pod undocumented
428 90 my %to_factorize;
429 90 ▶ if ($factorize eq 'all') {
Branch: 2 branches
BranchTrueFalseTotal
if ($factorize eq 'all') { } 89 1 90
elsif ($factorize ne 'none') { } 0 1 1
430 89 %to_factorize = %may_factorize;
431 }
432 elsif ($factorize ne 'none') {
433 0 my @factorize = split /,/,$factorize;
434 0 foreach my $prop (@factorize) {
435 0 ▶ if ($may_factorize{$prop}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($may_factorize{$prop}) { } 0 0 0
436 0 $to_factorize{$prop} = $may_factorize{$prop};
437 } else {
438 0 carp "unexpected item to factorize: $prop. Expected ".
439 join(' ', sort keys %may_factorize);
440 }
441 }
442 }
443 90 return \%to_factorize;
444 }
445  
446 90 ▶sub move_properties_out_of_element ($model, $to_factorize) {
Subroutine move_properties_out_of_element: called CC=8 SCAR=20.8
Pod undocumented
447 90 my $moved;
448 90 for my $prop (sort keys $to_factorize->%*) {
449 445 ▶ $moved->{$prop} = $model->{$prop} // {};
Condition100%2/2
$model->{$prop} // {}
l!l
1444
MC/DC100%1/1
$model->{$prop} // {}
$model->{$prop}
Truth table100%2/2
A
A= $model->{$prop}
Aresult
11
00
450 445 ▶ next unless defined $model->{element};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $model->{"element"} 15 430 445
451  
452 430 ▶ for (my $idx = 0; $idx < $model->{element}->@*; $idx+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @{$model->{"element"}}) 2870 430 3300
453 2870 my $elt_name = $model->{element}[$idx];
454 2870 my $data = $model->{element}[$idx+1];
455 2870 ▶ if (ref $data and $data->{$prop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data and $data->{$prop}) 380 2490 2870
Condition66%2/3
ref $data and $data->{$prop}
!ll&&!rl&&r
02490380
MC/DC50%1/2
ref $data and $data->{$prop}
ref $data $data->{$prop}
Truth table66%2/3
A and B
A= ref $dataB= $data->{$prop}
ABresult
0X0
100
111
456 380 $moved->{$prop}{$elt_name} = delete $data->{$prop};
457 }
458 }
459 430 ▶ if (keys $moved->{$prop}->%* > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$moved{$prop}} > 0) 92 338 430
460 92 $model->{$prop} = $moved->{$prop};
461 }
462 }
463 }
464  
465 # transform { eltA => data, eltB => data}
466 # in { eltA => data, eltB => '*eltA' }
467 268 ▶sub factorize_with_alias ($property_set) {
Subroutine factorize_with_alias: called CC=6 SCAR=17.9
Pod undocumented
468 268 ▶ return unless defined $property_set;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $property_set 203 65 268
469 65 my %equiv;
470 65 foreach my $property_name (sort keys $property_set->%*) {
471 272 my $property_data = $property_set->{$property_name};
472  
473 272 my $found;
474 272 foreach my $equiv_key (sort keys %equiv) {
475 933 ▶ if (Compare($property_data, $equiv{$equiv_key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (Compare($property_data, $equiv{$equiv_key})) 39 894 933
476 39 $found = $equiv_key;
477 39 last;
478 }
479 }
480 272 ▶ if ($found) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 39 233 272
481 39 $property_set->{$property_name} = "*$found";
482 }
483 else {
484 233 $equiv{$property_name} = $property_data;
485 }
486 }
487 }
488  
489 # transform { eltA => str, eltB => other, eltC => str}
490 # in { str => [eltA, eltC], other => eltB }
491 179 ▶sub factorize_reverse_packed ($property_set) {
Subroutine factorize_reverse_packed: called CC=6 SCAR=18.0
Pod undocumented
492 179 ▶ return unless defined $property_set;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $property_set 150 29 179
493 29 my %old = $property_set->%*;
494 29 my %new;
495  
496 29 foreach my $property_name (sort keys %old) {
497 117 my $property_data = $old{$property_name};
498 117 ▶ if (ref $property_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $property_data) 0 117 117
499 0 carp "value of $property_name is not a scalar";
500 }
501  
502 117 ▶ if (not exists $new{$property_data}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $new{$property_data}) { } 31 86 117
elsif (not ref $new{$property_data}) { } 18 68 86
503 31 $new{$property_data} = $property_name;
504 }
505 elsif (not ref $new{$property_data}) {
506 18 $new{$property_data} = [ $new{$property_data} , $property_name];
507 }
508 else {
509 68 push $new{$property_data}->@*, $property_name;
510 }
511 }
512 29 $property_set->%* = %new;
513 29 return;
514 }
515  
516 # this is similar to factorize_data, but the element order must be
517 # preserved.
518 91 ▶sub factorize_element ($factorized_element) {
Subroutine factorize_element: called CC=6 SCAR=18.0
Pod undocumented
519 91 ▶ return unless defined $factorized_element;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $factorized_element 3 88 91
520 88 my $previous_data;
521 my $previous_name;
522  
523 88 my @new;
524 88 ▶ for (my $idx = 0; $idx < $factorized_element->@*; $idx+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @$factorized_element) 584 88 672
525 584 my $name = $factorized_element->[$idx];
526 584 my $data = $factorized_element->[$idx+1];
527 584 ▶ if (Compare($data, $previous_data)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Compare($data, $previous_data)) { } 111 473 584
elsif (ref $data and not $data->{'alias'}) { } 473 0 473
528 111 push @new , { name => $name, alias => $previous_name };
529 }
530 ▶ elsif (ref $data and not $data->{alias}) {
Condition33%1/3
ref $data and not $data->{"alias"}
!ll&&!rl&&r
00473
MC/DC0%0/2
ref $data and not $data->{"alias"}
ref $data not $data->{"alias"}
Truth table33%1/3
A and not(B)
A= ref $dataB= not $data->{"alias"}
ABresult
0X0
100
111
531 473 push @new , { name => $name, $data->%* };
532 473 $previous_name = $name;
533 473 $previous_data = $data;
534 }
535 # else $data is already an alias
536 }
537  
538 88 return \@new;
539 }
540  
541 5 ▶sub write_app_files {
Subroutine write_app_files: called CC=6 SCAR=17.9
Pod undocumented
542 5 my $self = shift;
543  
544 5 my $app_dir = $self->cm_lib_dir;
545 5 my $app_obj = $self->meta_root->fetch_element('application');
546  
547 5 foreach my $app_name ( $app_obj->fetch_all_indexes ) {
548 5 $logger->debug("writing $app_name...");
549 5 my $app = $app_obj->fetch_with_id($app_name);
550 5 my $cat_dir_name = $app->fetch_element_value( name =>'category' ).'.d';
551 5 $app_dir->child($cat_dir_name)->mkdir();
552 5 my $app_file = $app_dir->child($cat_dir_name)->child($app->index_value) ;
553  
554 5 my @lines ;
555 5 foreach my $name ( $app->children ) {
556 55 ▶ next if $name eq 'category'; # saved as directory above
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "category" 5 50 55
557  
558 50 my $v = $app->fetch_element_value($name); # need to spit out 0 ?
559 50 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 40 10 50
560 10 push @lines, "$name = $v\n";
561  
562 }
563 5 $logger->info("writing file ".$app_file);
564 5 $app_file->spew(@lines);
565 5 delete $self->{app_map}{$app_name};
566 }
567  
568 # prune removed app files
569 5 foreach my $old_file ( values %{$self->{app_map}}) {
570 1 $logger->debug("Removing $old_file.");
571 1 $old_file->remove;
572 }
573 5 return;
574 }
575  
576 5 ▶sub write_all ($self, %args) {
Subroutine write_all: called CC=9 SCAR=22.0
Pod documented
577 5 my $root_obj = $self->meta_root ;
578 5 my $dir = $self->model_dir ;
579 5 ▶ my $factorize = delete $args{factorize} // 'all';
Condition50%1/2
delete $args{"factorize"} // "all"
l!l
05
MC/DC0%0/1
delete $args{"factorize"} // "all"
delete $args{"factorize"}
Truth table50%1/2
A
A= delete $args{"factorize"}
Aresult
11
00
580  
581 5 ▶ croak "write_all: unexpected parameters ",join(' ', keys %args) if %args ;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 5 5
582  
583 5 $self->write_app_files;
584  
585 5 my $map = $self->{map} ;
586  
587 5 $dir->mkdir;
588  
589 # get list of all classes loaded by the editor
590 my %loaded_classes
591 5 = map { ($_ => 1); }
592 $root_obj->fetch_element('class')->fetch_all_indexes ;
593  
594 # remove classes that are listed in map
595 5 foreach my $file (keys %$map) {
596 28 foreach my $class_name (@{$map->{$file}}) {
597 62 delete $loaded_classes{$class_name} ;
598 }
599 }
600  
601 # add remaining classes in map
602 5 my %new_map;
603 5 foreach my $class (keys %loaded_classes) {
604 25 my $f = $class =~ s!::!/!gr;
605 25 $new_map{"$f.pl"} = [ $class ] ;
606 }
607  
608 5 my %map_to_write = (%$map,%new_map) ;
609  
610 5 foreach my $file (keys %map_to_write) {
611 53 my $data = $self->check_model_to_write($file, $factorize, \%map_to_write, \%loaded_classes);
612 53 ▶ next unless @$data ; # don't write empty model
Branch: 1 branch
BranchTrueFalseTotal
unless @$data 1 52 53
613 52 write_perl_model_file ($dir->child($file), $self->{header}{$file}, $data);
614 52 delete $map_to_write{$file};
615 }
616  
617 # remove existing files that contain only deleted classes
618 5 foreach my $goner (sort keys %map_to_write) {
619 1 $logger->debug("Removing model file $goner.");
620 1 $dir->child($goner)->remove;
621 }
622 5 $self->meta_instance->clear_changes ;
623 5 return;
624 }
625  
626 53 ▶sub check_model_to_write ($self, $file, $factorize, $map_to_write, $loaded_classes) {
Subroutine check_model_to_write: called CC=7 SCAR=19.6
Pod undocumented
627 53 $logger->info("checking model file $file");
628  
629 53 my @data ;
630 53 my $file_needs_write = 0;
631  
632 # check if any a class of a file was modified
633 53 foreach my $class_name (@{$map_to_write->{$file}}) {
634 87 ▶ $file_needs_write++ if $self->class_needs_write($class_name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->class_needs_write($class_name) 87 0 87
635 87 $logger->info("file $file class $class_name needs write ",$file_needs_write);
636 }
637  
638 53 ▶ if ($file_needs_write) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file_needs_write) 53 0 53
639 53 foreach my $class_name (@{$map_to_write->{$file}}) {
640 87 $logger->info("writing class $class_name");
641 87 my $model = $self-> get_perl_data_model($class_name, $factorize) ;
642 87 ▶ push @data, $model if defined $model and keys %$model;
Branch: 1 branch
BranchTrueFalseTotal
if defined $model and keys %$model 86 1 87
Condition66%2/3
defined $model and keys %$model
!ll&&!rl&&r
1086
MC/DC50%1/2
defined $model and keys %$model
defined $model keys %$model
Truth table66%2/3
A and B
A= defined $modelB= keys %$model
ABresult
0X0
100
111
643  
644 # remove class name from above list
645 87 delete $loaded_classes->{$class_name} ;
646 }
647 }
648  
649 53 return \@data;
650 }
651  
652 2 ▶sub write_model_plugin ($self, %args) {
Subroutine write_model_plugin: called CC=6 SCAR=18.2
Pod documented
653 my $plugin_dir = delete $args{plugin_dir}
654 2 ▶ || croak __PACKAGE__," write_model_plugin: undefined plugin_dir";
Condition50%1/2
delete $args{'plugin_dir'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_dir')
l!l
20
MC/DC0%0/1
delete $args{'plugin_dir'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_dir')
delete $args{'plugin_dir'}
Truth table50%1/2
A
A= delete $args{'plugin_dir'}
Aresult
11
00
655 my $plugin_name = delete $args{plugin_name}
656 2 ▶ || croak __PACKAGE__," write_model_plugin: undefined plugin_name";
Condition50%1/2
delete $args{'plugin_name'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_name')
l!l
20
MC/DC0%0/1
delete $args{'plugin_name'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_name')
delete $args{'plugin_name'}
Truth table50%1/2
A
A= delete $args{'plugin_name'}
Aresult
11
00
657 2 ▶ croak "write_model_plugin: unexpected parameters ",join(' ', keys %args) if %args ;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 2 2
658  
659 2 my $model = $self->meta_root->dump_as_data(mode => 'custom') ;
660 # print (Dumper( $model)) ;
661  
662 2 ▶ my @raw_data = @{$model->{class} || []} ;
Condition50%1/2
$model->{'class'} || []
l!l
20
MC/DC0%0/1
$model->{'class'} || []
$model->{'class'}
Truth table50%1/2
A
A= $model->{'class'}
Aresult
11
00
663 2 ▶ while (@raw_data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@raw_data) 4 2 6
664 4 my ( $class , $data ) = splice @raw_data,0,2 ;
665 4 $data->{name} = $class ;
666  
667 4 my $plugin_file = $class.'.pl';
668 4 $plugin_file =~ s!::!/!g;
669 4 write_perl_model_file ($plugin_dir->child($plugin_name)->child($plugin_file), [], [ $data ]);
670 }
671  
672 2 $self->meta_instance->clear_changes ;
673 2 return;
674 }
675  
676 1 ▶sub read_model_plugin ($self, %args) {
Subroutine read_model_plugin: called CC=5 SCAR=16.6
Pod documented
677 my $plugin_dir = delete $args{plugin_dir}
678 1 ▶ || croak __PACKAGE__," write_model_plugin: undefined plugin_dir";
Condition50%1/2
delete $args{'plugin_dir'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_dir')
l!l
10
MC/DC0%0/1
delete $args{'plugin_dir'} || croak(__PACKAGE__, ' write_model_plugin: undefined plugin_dir')
delete $args{'plugin_dir'}
Truth table50%1/2
A
A= delete $args{'plugin_dir'}
Aresult
11
00
679 my $plugin_name = delete $args{plugin_name}
680 1 ▶ || croak __PACKAGE__," read_model_plugin: undefined plugin_name";
Condition50%1/2
delete $args{'plugin_name'} || croak(__PACKAGE__, ' read_model_plugin: undefined plugin_name')
l!l
10
MC/DC0%0/1
delete $args{'plugin_name'} || croak(__PACKAGE__, ' read_model_plugin: undefined plugin_name')
delete $args{'plugin_name'}
Truth table50%1/2
A
A= delete $args{'plugin_name'}
Aresult
11
00
681  
682 1 ▶ croak "read_model_plugin: unexpected parameters ",join(' ', keys %args) if %args ;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 1 1
683  
684 1 my @files ;
685 4 ▶ my $wanted = sub ($path, $) {
Subroutine __ANON__: called CC=6 SCAR=18.7
686 4 ▶ if ($path->is_file
Branch: 1 branch
BranchTrueFalseTotal
if ($path->is_file and not /~$/u and not /CVS/u and not /.(orig|pod)$/u and m[\.d/$plugin_name]u) 2 2 4
Condition66%8/12
$path->is_file and not /~$/u and not /CVS/u and not /.(orig|pod)$/u and m[\.d/$plugin_name]u
!ll&&!rl&&r
202
$path->is_file and not /~$/u and not /CVS/u and not /.(orig|pod)$/u
!ll&&!rl&&r
202
$path->is_file and not /~$/u and not /CVS/u
!ll&&!rl&&r
202
$path->is_file and not /~$/u
!ll&&!rl&&r
202
MC/DC20%1/5
$path->is_file and not /~$/u and not /CVS/u and not /.(orig|pod)$/u and m[\.d/$plugin_name]u
$path->is_file not /~$/u not /CVS/u not /.(orig|pod)$/u m[\.d/$plugin_name]u
Truth table33%2/6
A and not(B) and not(C) and not(D) and E
A= $path->is_fileB= not /~$/uC= not /CVS/uD= not /.(orig|pod)$/uE= m[\.d/$plugin_name]u
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
687 and not /~$/
688 and not /CVS/
689 and not m!.(orig|pod)$!
690 and m!\.d/$plugin_name!
691 ) {
692 2 say "add $path";
693 2 push @files, $path;
694 }
695 1 } ;
696 1 path($plugin_dir)->visit($wanted, { recurse => 1 } ) ;
697  
698 1 foreach my $load_file (@files) {
699 2 $self->read_plugin_file($load_file);
700 }
701 1 return;
702 }
703  
704 2 ▶sub read_plugin_file {
Subroutine read_plugin_file: called CC=5 SCAR=20.4
Pod undocumented
705 2 my ($self, $load_file) = @_;
706  
707 2 $logger->info("trying to read plugin $load_file");
708 2 my $class_element = $self->meta_root->fetch_element('class') ;
709  
710 2 my $plugin = do $load_file->absolute ;
711  
712 2 ▶ unless ($plugin) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin) 0 2 2
713 0 ▶ if ($@) {die "couldn't parse $load_file: $@"; }
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not defined $plugin) { } 0 0 0
714 0 elsif (not defined $plugin) {die "couldn't do $load_file: $!"}
715 0 else { die "couldn't run $load_file" ;}
716 }
717  
718 # there should be only only class in each plugin file
719 2 foreach my $model (@$plugin) {
720 2 my $class_name = delete $model->{name} ;
721 # load with a array ref to avoid warnings about missing order
722 2 $class_element->fetch_with_id($class_name)->load_data( $model ) ;
723 }
724  
725 2 return;
726 }
727  
728 56 ▶sub write_perl_model_file {
Subroutine write_perl_model_file: called CC=1 SCAR=0.0
Pod undocumented
729 56 my $wr_file = shift; # Path::Tiny object
730 56 my $comments = shift ;
731 56 my $data = shift;
732  
733 56 $wr_file->parent->mkdir();
734  
735 56 $logger->info("in $wr_file");
736  
737 56 my $dumper = Data::Dumper->new( [ \@$data ] );
738 56 $dumper->Indent(1); # avoid too deep indentation
739 56 $dumper->Terse(1); # allow unnamed variables in dump
740 56 $dumper->Sortkeys(1); # sort keys in hash
741  
742 56 my $dump = $dumper->Dump;
743  
744 # split pod strings to break text that could be confused as pod markup
745 56 $dump =~ s/\n=/\n'.'=/g;
746  
747 56 $wr_file->spew_utf8(
748 @$comments,
749 "use strict;\n",
750 "use warnings;\n",
751 "use v5.20;\n",
752 "use utf8;\n\n",
753 "return $dump;\n",
754 );
755  
756 56 return;
757 }
758  
759  
760  
761 1 ▶sub list_class_element {
Subroutine list_class_element: called CC=3 SCAR=11.0
Pod documented
762 1 my $self = shift ;
763 1 ▶ my $pad = shift || '' ;
Condition50%1/2
shift() || ''
l!l
01
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
764  
765 1 my $res = '';
766 1 my $meta_class = $self->{meta_root}->fetch_element('class') ;
767 1 foreach my $class_name ($meta_class->fetch_all_indexes ) {
768 20 $res .= $self->list_one_class_element($class_name) ;
769 }
770 1 return $res ;
771 }
772  
773 36 ▶sub list_one_class_element {
Subroutine list_one_class_element: called CC=12 SCAR=24.9
Pod undocumented
774 36 my $self = shift ;
775 36 ▶ my $class_name = shift || return '' ;
Condition50%1/2
shift() || (return '')
l!l
360
MC/DC0%0/1
shift() || (return '')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
776 36 ▶ my $pad = shift || '' ;
Condition100%2/2
shift() || ''
l!l
1620
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
777  
778 36 my $res = $pad."Class: $class_name\n";
779 36 my $meta_class = $self->{meta_root}->fetch_element('class')
780 -> fetch_with_id($class_name) ;
781  
782 36 my @elts = $meta_class->fetch_element('element')->fetch_all_indexes ;
783  
784 36 my @include = $meta_class->fetch_element('include')->fetch_all_values ;
785 36 my $inc_after = $meta_class->grab_value('include_after') ;
786  
787 36 ▶ if (@include and not defined $inc_after) {
Branch: 1 branch
BranchTrueFalseTotal
if (@include and not defined $inc_after) 7 29 36
Condition100%3/3
@include and not defined $inc_after
!ll&&!rl&&r
2367
MC/DC100%2/2
@include and not defined $inc_after
@include not defined $inc_after
Truth table100%3/3
A and not(B)
A= @includeB= not defined $inc_after
ABresult
0X0
100
111
788 7 foreach my $inc (@include) {
789 7 $res .= $self->list_one_class_element($inc,$pad.' ') ;
790 }
791 }
792  
793 36 ▶ return $res unless @elts ;
Branch: 1 branch
BranchTrueFalseTotal
unless @elts 0 36 36
794  
795 36 foreach my $elt_name ( @elts) {
796 347 my $type = $meta_class->grab_value("element:$elt_name type") ;
797  
798 347 $res .= $pad." - $elt_name ($type)\n";
799 347 ▶ if (@include and defined $inc_after and $inc_after eq $elt_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (@include and defined $inc_after and $inc_after eq $elt_name) 6 341 347
Condition100%6/6
@include and defined $inc_after and $inc_after eq $elt_name
!ll&&!rl&&r
303386
@include and defined $inc_after
!ll&&!rl&&r
2297444
MC/DC100%3/3
@include and defined $inc_after and $inc_after eq $elt_name
@include defined $inc_after $inc_after eq $elt_name
Truth table100%4/4
A and B and C
A= @includeB= defined $inc_afterC= $inc_after eq $elt_name
ABCresult
0XX0
10X0
1100
1111
800 6 foreach my $inc (@include) {
801 9 $res .= $self->list_one_class_element($inc,$pad.' ') ;
802 }
803 }
804 }
805 36 return $res ;
806 }
807  
808  
809 1 ▶sub get_dot_diagram {
Subroutine get_dot_diagram: called CC=4 SCAR=13.9
Pod documented
810 1 my $self = shift ;
811 1 my $dot = "digraph model {\n" ;
812  
813 1 my $meta_class = $self->{meta_root}->fetch_element('class') ;
814 1 foreach my $class_name ($meta_class->fetch_all_indexes ) {
815 20 my $d_class = $class_name ;
816 20 $d_class =~ s/::/__/g;
817  
818 20 my $elt_list = '';
819 20 my $use = '';
820  
821 20 my $class_obj = $self->{meta_root}->grab(qq!class:"$class_name"!);
822 20 my @elts = $class_obj ->grab(qq!element!) ->fetch_all_indexes ;
823 20 foreach my $elt_name ( @elts ) {
824 132 my $of = '';
825 132 my $elt_obj = $class_obj->grab(qq!element:"$elt_name"!) ;
826 132 my $type = $elt_obj->grab_value("type") ;
827 132 ▶ if ($type =~ /^list|hash$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^list|hash$/u) { } 28 104 132
828 28 my $cargo = $elt_obj->grab("cargo");
829 28 my $ct = $cargo->grab_value("type") ;
830 28 $of = " of $ct" ;
831 28 $use .= $self->scan_used_class($d_class,$elt_name,$cargo);
832 }
833 else {
834 104 $use .= $self->scan_used_class($d_class,$elt_name,$elt_obj);
835 }
836 132 $elt_list .= "- $elt_name ($type$of)\\n";
837 }
838  
839 20 $dot .= $d_class
840 . qq! [shape=box label="$class_name\\n$elt_list"];\n!
841 . $use . "\n";
842  
843 20 $dot .= $self->scan_includes($class_name, $class_obj) ;
844 }
845  
846 1 $dot .="}\n";
847  
848 1 return $dot ;
849 }
850  
851 20 ▶sub scan_includes {
Subroutine scan_includes: called CC=2 SCAR=6.9
Pod undocumented
852 20 my ($self,$class_name, $class_obj) = @_ ;
853 20 my $d_class = $class_name ;
854 20 $d_class =~ s/::/__/g;
855  
856 20 my @includes = $class_obj->grab('include')->fetch_all_values ;
857 20 my $dot = '';
858 20 foreach my $c (@includes) {
859 10 say "$class_name includes $c";
860 10 my $t = $c;
861 10 $t =~ s/::/__/g;
862 10 $dot.= qq!$d_class -> $t ;\n!;
863 }
864 20 return $dot;
865 }
866  
867 132 ▶sub scan_used_class {
Subroutine scan_used_class: called CC=1 SCAR=0.0
Pod undocumented
868 132 my ($self,$d_class,$elt_name, $elt_obj) = @_ ;
869  
870 # define leaf call back
871 3299 ▶ my $disp_leaf = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
872 3299 my ($scanner, $data_ref, $node,$element_name,$index, $leaf_object) = @_ ;
873 3299 ▶ return unless $element_name eq 'config_class_name';
Branch: 1 branch
BranchTrueFalseTotal
unless $element_name eq "config_class_name" 3270 29 3299
874 29 my $v = $leaf_object->fetch;
875 29 ▶ return unless $v;
Branch: 1 branch
BranchTrueFalseTotal
unless $v 7 22 29
876 22 $v =~ s/::/__/g;
877 22 $$data_ref .= qq!$d_class -> $v !
878 . qq![ style=dashed, label="$elt_name" ];\n!;
879 132 } ;
880  
881 # simple scanner, (print all values)
882 132 my $scan = Config::Model::ObjTreeScanner-> new (
883 leaf_cb => $disp_leaf, # only mandatory parameter
884 ) ;
885  
886 132 my $result = '' ;
887 132 $scan->scan_node(\$result, $elt_obj) ;
888 132 return $result ;
889 }
890  
891 11 __PACKAGE__->meta->make_immutable;
892  
893 11 1;
894  
895  
896 # ABSTRACT: Model (or schema) editor for Config::Model
897  
898 __END__
« blib/lib/Config/Model/Itself/TkEditUI.pm ↑ Summary blib/lib/Config/Model/Itself/BackendDetector.pm »