1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
--- a/lib/Config/Model/CheckList.pm
+++ b/lib/Config/Model/CheckList.pm
@@ -12,10 +12,12 @@
$Config::Model::CheckList::VERSION = '2.021';
}
use Any::Moose ;
+use 5.010 ;
use Config::Model::Exception ;
use Config::Model::IdElementReference ;
use Config::Model::Warper ;
+use List::MoreUtils qw/any none/;
use Carp;
use Log::Log4perl qw(get_logger :levels);
use Storable qw/dclone/;
@@ -459,7 +461,17 @@
my $ud = $self->{upstream_default_data} ;
# copy hash and return it
- my %std = (%h, %$ud, %$lay, %$def, %$pre ) ;
+ my %predef = (%h, %$def, %$pre ) ;
+ my %std = (%h, %$ud, %$lay, %$def, %$pre ) ;
+
+ # use _std_backup if all data values are null (no checked items by user)
+ my %old_dat = (none { $_ ;} values %$dat) ? %{$self->{_std_backup} || {}} : %$dat ;
+
+ if (not $mode and any {$_;} values %predef and none { $_ ;} values %old_dat) {
+ # changed from nothing to default checked list that must be written
+ $self->{_std_backup} = \%predef ;
+ $self->notify_change(note => "use default checklist") ;
+ }
# custom test must compare the whole list at once, not just one item at a time.
my %result
@@ -469,7 +481,7 @@
: $mode eq 'upstream_default' ? (%h, %$ud)
: $mode eq 'default' ? (%h, %$def )
: $mode eq 'standard' ? %std
- : (%h, %$def, %$pre, %$dat );
+ : (%predef, %$dat );
return wantarray ? %result : \%result;
}
--- a/t/check_list.t
+++ b/t/check_list.t
@@ -10,7 +10,7 @@
use Data::Dumper;
use Log::Log4perl qw(:easy :levels) ;
-BEGIN { plan tests => 87; }
+BEGIN { plan tests => 91; }
use strict;
@@ -418,18 +418,23 @@
"test upstream_default of choice_list_with_upstream_default" );
# test check list with upstream_default *and* default (should override)
+$inst->clear_changes ;
my $wudad =
$root->fetch_element("choice_list_with_default_and_upstream_default");
+is($inst->needs_save,0,"check needs_save after reading a default value") ;
@got = $wudad->get_checked_list('default');
is_deeply( \@got, [qw/A C/],
"test default of choice_list_with_default_and_upstream_default" );
+is($inst->needs_save,0,"check needs_save after reading a default value") ;
@got = $wudad->get_checked_list();
is_deeply( \@got, [qw/A C/],
"test choice_list_with_default_and_upstream_default" );
+is($inst->needs_save,1,"check needs_save after reading a default value") ;
is_deeply( $wudad->fetch(), 'A,C',
"test fetch choice_list_with_default_and_upstream_default" );
+is($inst->needs_save,1,"check needs_save after reading a default value") ;
### test preset feature
--- a/lib/Config/Model/Node.pm
+++ b/lib/Config/Model/Node.pm
@@ -1083,7 +1083,7 @@
sub migrate {
my $self = shift ;
$self->init ;
- Config::Model::Dumper->new->dump_tree(node => $self, mode => 'custom', @_) ;
+ Config::Model::Dumper->new->dump_tree(node => $self, mode => 'full', @_) ;
return $self->needs_save ;
}
|