Config-Augeas
view release on metacpan or search on metacpan
2008-11-16 Domi <domi@bilbo.maison>
* lib/Config/Augeas.pm (set): no longer dies when trying to set a
value to 0. Only dies when the value to set is undefined.
2008-11-07 Dominique Dumont <dominique.dumont@hp.com> v0.303
* Build.PL: Require Augeas 0.3.4 minimum
* t/Config-AugeasC.t: Added tests cases for save with backup and
save without backup. Fixed sshd_config tests
2008-10-26 Dominique Dumont <domi.dumont@free.fr> v0.302
* t/Config-AugeasC.t: Starting from version 0.3.2, Augeas no
longer writes a file when its data was not modified. This change
of behavior broke this test. This test is now fixed to cope with
this change (which makes sense).
2008-08-29 Dominique Dumont <dominique.dumont@hp.com> v0.301
lib/Config/Augeas.pm view on Meta::CPAN
a colon-spearated list of directories that lenses should be searched
in. This is in addition to the standard load path and the directories
in specified C<AUGEAS_LENS_LIB> environment variable.
=item root
Use C<root> as the filesystem root. If not specified, use the value of
the environment variable C<AUGEAS_ROOT>. If that doesn't exist either,
use "C</>".
=item save => backup | newfile | noop
Specify how to save the configuration file. Either create a newfile
(with extension C<.augnew>, and do not overwrite the original file) or
move the original file into a backup file (C<.augsave> extension).
C<noop> make saves a no-op process, just record what would have
changed
=item type_check => 1
Typecheck lenses; since it can be very expensive it is not done by
default.
=item no_std_inc
lib/Config/Augeas.pm view on Meta::CPAN
sub new {
my $type = shift ;
my $self = {} ;
my %args = @_ ;
my $flags = 0 ;
my $loadpath = delete $args{loadpath} || '';
my $root = delete $args{root} || '';
my $save = delete $args{save} || '';
if ($save eq 'backup') { $flags |= &AUG_SAVE_BACKUP }
elsif ($save eq 'newfile') { $flags |= &AUG_SAVE_NEWFILE }
elsif ($save =~ 'noop') { $flags |= &AUG_SAVE_NOOP }
elsif ($save) {
croak __PACKAGE__," new: unexpected save value: $save. ",
"Expected backup or newfile";
}
$flags |= &AUG_TYPE_CHECK if ( delete $args{type_check} || 0 );
$flags |= &AUG_NO_STDINC if ( delete $args{no_std_inc} || 0 ) ;
$flags |= &AUG_NO_LOAD if ( delete $args{no_load} || 0 ) ;
$flags |= &AUG_ENABLE_SPAN if ( delete $args{enable_span} || 0 ) ;
croak __PACKAGE__," new: unexpected parameters: ",
join (' ',keys %args)
if %args ;
lib/Config/Augeas.pm view on Meta::CPAN
# Augeas 0.4.0 is a little picky about trailing slashes
$pattern =~ s!/$!!;
return $self->{aug_c} -> count_match($pattern) ;
}
=head2 save
Write all pending changes to disk. Return 0 if an error is
encountered, 1 on success. Only files that had any changes made to
them are written. C<save> will follow backup files as specified with
Config::Augeas::new C<backup> parameter.
=cut
sub save {
my $self = shift ;
my $ret = $self->{aug_c} -> save() ;
return $ret == 0 ? 1 : 0 ;
}
=head2 load
t/Config-AugeasC.t view on Meta::CPAN
copy($r_root.'etc/ssh/sshd_config',$aug_root.'etc/ssh/')
|| die "Can't copy etc/ssh/sshd_config:$!" ;
foreach my $f (qw!hosts ssh/sshd_config!) {
my $testfile = $aug_root."etc/$f" ;
next if -r $testfile ;
die "Cannot test: file $testfile was not written";
}
}
# test augeas without backup file
cleanup;
my $h_file = $aug_root."etc/hosts" ;
my $h_size = stat($h_file)->size ;
my $aug = Config::Augeas::init($aug_root, '' ,0) ;
ok($aug,"Created new Augeas object without backup file");
my $ret = $aug->set("/files/etc/hosts/2/canonical","bilbobackup") ;
is($ret,0,"Set new host name");
$ret = $aug->save ;
is($ret,0,"Save with backup done") ;
is( stat($h_file)->size , $h_size + 6 , "Check new file size") ;
# test augeas with backup file
cleanup;
my $augb = Config::Augeas::init($aug_root, '' ,
&Config::Augeas::AUG_SAVE_BACKUP) ;
ok($augb,"Created new Augeas object with backup file");
$ret = $augb->set("/files/etc/hosts/2/canonical","bilbobackup") ;
is($ret,0,"Set new host name");
$ret = $augb->save ;
is($ret,0,"Save with backup done") ;
my $b_file = $h_file.".augsave" ;
ok( -e $b_file , "Backup file was written" ) ;
is( stat($b_file)->size , $h_size, "compare file sizes") ;
# complete test with save file
cleanup ;
( run in 1.423 second using v1.01-cache-2.11-cpan-49f99fa48dc )