r28581 - in /branches/upstream/libconfig-model-perl/current: ChangeLog META.yml lib/Config/Model.pm lib/Config/Model/AutoRead.pm t/auto_read.t
ddumont-guest at users.alioth.debian.org
ddumont-guest at users.alioth.debian.org
Tue Dec 23 15:57:46 UTC 2008
Author: ddumont-guest
Date: Tue Dec 23 15:57:42 2008
New Revision: 28581
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=28581
Log:
[svn-upgrade] Integrating new upstream version, libconfig-model-perl (0.633)
Modified:
branches/upstream/libconfig-model-perl/current/ChangeLog
branches/upstream/libconfig-model-perl/current/META.yml
branches/upstream/libconfig-model-perl/current/lib/Config/Model.pm
branches/upstream/libconfig-model-perl/current/lib/Config/Model/AutoRead.pm
branches/upstream/libconfig-model-perl/current/t/auto_read.t
Modified: branches/upstream/libconfig-model-perl/current/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-model-perl/current/ChangeLog?rev=28581&op=diff
==============================================================================
--- branches/upstream/libconfig-model-perl/current/ChangeLog (original)
+++ branches/upstream/libconfig-model-perl/current/ChangeLog Tue Dec 23 15:57:42 2008
@@ -1,3 +1,11 @@
+2008-12-23 Dominique Dumont <dominique.dumont at hp.com> v0.633
+
+ * lib/Config/Model/AutoRead.pm : Added -allow_empty parameter so
+ starting a configuration from scratch can be allowed by
+ configuration model designer. No longer die if 'augeas'
+ backend (or any other optional backend) is not found. Just emit a
+ warning.
+
2008-12-16 Dominique Dumont <dominique.dumont at hp.com> v0.632
* config-edit: added -backend parameter so (advanced) user can
Modified: branches/upstream/libconfig-model-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-model-perl/current/META.yml?rev=28581&op=diff
==============================================================================
--- branches/upstream/libconfig-model-perl/current/META.yml (original)
+++ branches/upstream/libconfig-model-perl/current/META.yml Tue Dec 23 15:57:42 2008
@@ -1,6 +1,6 @@
---
name: Config-Model
-version: 0.632
+version: 0.633
author:
- Dominique Dumont (ddumont at cpan dot org)
abstract: Edit and validate configuration data
@@ -24,7 +24,7 @@
provides:
Config::Model:
file: lib/Config/Model.pm
- version: 0.632
+ version: 0.633
Config::Model::AnyId:
file: lib/Config/Model/AnyId.pm
version: 1.0793
@@ -33,7 +33,7 @@
version: 1.0660
Config::Model::AutoRead:
file: lib/Config/Model/AutoRead.pm
- version: 1.0814
+ version: 1.0819
Config::Model::CheckList:
file: lib/Config/Model/CheckList.pm
version: 1.0775
Modified: branches/upstream/libconfig-model-perl/current/lib/Config/Model.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-model-perl/current/lib/Config/Model.pm?rev=28581&op=diff
==============================================================================
--- branches/upstream/libconfig-model-perl/current/lib/Config/Model.pm (original)
+++ branches/upstream/libconfig-model-perl/current/lib/Config/Model.pm Tue Dec 23 15:57:42 2008
@@ -1,6 +1,6 @@
# $Author: ddumont $
-# $Date: 2008-12-16 14:18:45 +0100 (Tue, 16 Dec 2008) $
-# $Revision: 814 $
+# $Date: 2008-12-23 16:33:45 +0100 (Tue, 23 Dec 2008) $
+# $Revision: 819 $
# Copyright (c) 2005-2008 Dominique Dumont.
#
@@ -34,7 +34,7 @@
# this class holds the version number of the package
use vars qw($VERSION @status @level @experience_list %experience_index) ;
-$VERSION = '0.632';
+$VERSION = '0.633';
=head1 NAME
@@ -1475,10 +1475,6 @@
Dominique Dumont, (ddumont at cpan dot org)
-=head1 SEE ALSO
-
-L<Config::Model::Instance>,
-
=head1 LICENSE
Copyright (c) 2005-2008 Dominique Dumont.
@@ -1499,6 +1495,10 @@
along with Config-Model; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
+
+=head1 SEE ALSO
+
+L<Config::Model::Instance>,
=head2 Model elements
Modified: branches/upstream/libconfig-model-perl/current/lib/Config/Model/AutoRead.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-model-perl/current/lib/Config/Model/AutoRead.pm?rev=28581&op=diff
==============================================================================
--- branches/upstream/libconfig-model-perl/current/lib/Config/Model/AutoRead.pm (original)
+++ branches/upstream/libconfig-model-perl/current/lib/Config/Model/AutoRead.pm Tue Dec 23 15:57:42 2008
@@ -1,6 +1,6 @@
# $Author: ddumont $
-# $Date: 2008-12-16 14:18:45 +0100 (Tue, 16 Dec 2008) $
-# $Revision: 814 $
+# $Date: 2008-12-23 16:33:45 +0100 (Tue, 23 Dec 2008) $
+# $Revision: 819 $
# Copyright (c) 2005-2008 Dominique Dumont.
#
@@ -36,7 +36,7 @@
use base qw/Config::Model::AnyThing/ ;
-our $VERSION = sprintf "1.%04d", q$Revision: 814 $ =~ /(\d+)/;
+our $VERSION = sprintf "1.%04d", q$Revision: 819 $ =~ /(\d+)/;
=head1 NAME
@@ -51,7 +51,8 @@
read_config => [ { backend => 'cds_file' , config_dir => '/etc/cfg_dir'},
{ backend => 'custom' , # dir hardcoded in custom class
- class => 'ProcessRead'
+ class => 'ProcessRead' ,
+ allow_empty => 1, # optional
}
],
# if omitted, write_config will be written using read_config specifications
@@ -200,8 +201,8 @@
=head2 read and write specification
-A configuration class will be declared with optional C<read> or
-C<write> parameters:
+A configuration class will be declared with optional C<read_config> or
+C<write_config> parameters:
read_config => [ { backend => 'cds_file', config_dir => '/etc/my_cfg/' } ,
{ backend => 'custom', class => 'Bar' },
@@ -228,7 +229,18 @@
=back
When a read operation is successful, the remaining read methods will
-be skipped.
+be skipped. By default, an exception is thrown if no read was
+successfull. This behavior can be overridden by specifying
+C<< allow_empty => 1 >> in one of the backend specification. For instance:
+
+ read_config => [ { backend => 'cds_file', config_dir => '/etc/my_cfg/' } ,
+ { backend => 'custom', class => 'Bar' ,
+ allow_empty => 1
+ },
+ ],
+
+This feature is necessary if you want to be able to create a
+configuration from scratch.
When necessary (or required by the user), all configuration
informations are written back using B<all> the write method passed.
@@ -305,6 +317,7 @@
my @list = ref $readlist eq 'ARRAY' ? @$readlist : ($readlist) ;
my $pref_backend = $instance->backend || '' ;
my $read_done = 0;
+ my $allow_empty = 0;
foreach my $read (@list) {
warn $self->config_class_name,
@@ -318,8 +331,10 @@
next if ($pref_backend and $backend ne $pref_backend) ;
- my $read_dir = delete $read->{config_dir} || $r_dir || ''; # r_dir obsolete
+ my $read_dir = delete $read->{config_dir} || $r_dir || ''; # $r_dir obsolete
$read_dir .= '/' if $read_dir and $read_dir !~ m(/$) ;
+
+ $allow_empty ||= delete $read->{allow_empty} if defined $read->{allow_empty};
if ($backend eq 'custom') {
my $c = my $file = delete $read->{class} ;
@@ -368,12 +383,9 @@
my $f = delete $read->{function} || 'read' ;
eval {require $file.'.pm' unless $c->can($f); } ;
if ($@) {
- Config::Model::Exception::Model -> throw
- (
- error=> "auto_read error: unknown backend '$backend'".
- ", cannot load Perl class $c: $@",
- object => $self
- ) ;
+ warn "auto_read: unknown backend '$backend'".
+ ", cannot load Perl class $c: $@\n";
+ next ;
}
no strict 'refs';
my $backend_obj = $self->{backend}{$backend} = $c->new(node => $self) ;
@@ -387,7 +399,7 @@
}
}
- if (not $read_done) {
+ if (not $read_done and not $allow_empty) {
Config::Model::Exception::Model -> throw
(
error => "auto_read error: could not read config file "
@@ -413,6 +425,7 @@
# root override is passed by the instance
my $root_dir = $instance -> write_root_dir || '';
+ my $registered_backend = 0;
# provide a proper write back function
my @array = ref $wrlist eq 'ARRAY' ? @$wrlist : ($wrlist) ;
@@ -486,12 +499,9 @@
my $f = $write->{function} || 'write' ;
eval {require $file.'.pm' unless $c->can($f); } ;
if ($@) {
- Config::Model::Exception::Model -> throw
- (
- error=> "auto_write error: unknown backend '$backend'".
- ", cannot load Perl class $c: $@",
- object => $self
- ) ;
+ warn "auto_write: unknown backend '$backend'".
+ ", cannot load Perl class $c: $@" unless $registered_backend;
+ next ;
}
my $safe_self = $self ; # provide a closure
@@ -510,6 +520,7 @@
}
$instance->register_write_back($backend => $wb) ;
+ $registered_backend ++ ;
}
}
Modified: branches/upstream/libconfig-model-perl/current/t/auto_read.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libconfig-model-perl/current/t/auto_read.t?rev=28581&op=diff
==============================================================================
--- branches/upstream/libconfig-model-perl/current/t/auto_read.t (original)
+++ branches/upstream/libconfig-model-perl/current/t/auto_read.t Tue Dec 23 15:57:42 2008
@@ -1,10 +1,10 @@
# -*- cperl -*-
# $Author: ddumont $
-# $Date: 2008-12-16 14:18:45 +0100 (Tue, 16 Dec 2008) $
-# $Revision: 814 $
+# $Date: 2008-12-23 16:33:45 +0100 (Tue, 23 Dec 2008) $
+# $Revision: 819 $
use ExtUtils::testlib;
-use Test::More tests => 49;
+use Test::More tests => 51;
use Config::Model;
use File::Path;
use File::Copy ;
@@ -29,14 +29,15 @@
# pseudo root for config files
-my $root1 = 'test_root1/';
-my $root2 = 'test_root2/';
+my $wr_root = 'wr_root' ;
+my $root1 = "$wr_root/test1/";
+my $root2 = "$wr_root/test2/";
+my $root3 = "$wr_root/test3/";
my $conf_dir = '/etc/test/';
# cleanup before tests
-rmtree($root1);
-rmtree($root2);
+rmtree($wr_root);
# model declaration
$model->create_config_class
@@ -57,7 +58,9 @@
# try first to read with cds string and then custom class
read_config => [ { backend => 'cds_file'},
- { backend => 'custom', class => 'Level1Read', function => 'read_it' } ],
+ { backend => 'custom',
+ class => 'Level1Read',
+ function => 'read_it' } ],
write_config => [ { backend => 'cds_file', config_dir => $conf_dir},
{ backend => 'perl_file', config_dir => $conf_dir},
{ backend => 'ini_file' , config_dir => $conf_dir}],
@@ -117,6 +120,19 @@
]
);
+$model->create_config_class
+ (
+ name => 'FromScratch',
+
+ read_config => [ { backend => 'cds_file', config_dir => $conf_dir,
+ allow_empty => 1},
+ ],
+
+ element => [
+ aa => { type => 'leaf',value_type => 'string'} ,
+ ]
+ );
+
# global variable to snoop on read config action
my %result;
@@ -371,3 +387,14 @@
} qr/read_config_dir is obsolete/ , "obsolete warning" ;
is( $dump, $expect_custom, "pl_test: check dump" );
+
+#create from scratch instance
+my $scratch_i = $model->instance(root_class_name => 'FromScratch',
+ instance_name => 'scratch_inst',
+ root_dir => $root3 ,
+ );
+ok($scratch_i,"Created instance from scratch to load cds files") ;
+
+$scratch_i->config_root->load("aa=toto") ;
+$scratch_i -> write_back ;
+ok ( -e "$root3/$conf_dir/scratch_inst.cds", "wrote cds config file") ;
More information about the Pkg-perl-cvs-commits
mailing list