[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] Newbie to augeas: Questions about perl interface



Hi,

First off, these are questions about the perl module Config::Augeas
currently maintained by Raphael Pinson. Please et me know If this
isn't the right list.

My questions are mostly about error reporting and $aug->set().

First, Config-Augeas-0.902/lib/Config/Augeas.pm has:

=head2 set ( path, value )

Set the value associated with C<path> to C<value>. C<value> is copied
into Augeas internal data structure. Intermediate entries are created
if they don't exist. Return 1 on success, 0 on error. It is an error
if more than one node matches C<path>.

=cut

sub set {
    my $self  = shift ;
    my $path  = shift || croak __PACKAGE__," set: undefined path";
    my $value = shift ;

    croak __PACKAGE__," set: undefined value" unless defined $value;

    my $result ;
    my $ret = $self->{aug_c} -> set($path,$value) ;

    return 1 if $ret == 0;

    $self -> print('/augeas') ;
    croak __PACKAGE__," set: error with path $path";
}

Hey! sub set {} *never* returns 0. If it doesn't return 1, it prints a
_large_ data structure to STDOUT and then croaks!!! Is there a good
reason for this? Is there a way to avoid this library printing to
STDOUT? As I see it, there is no way to  eval { $avg->set } without
having STDOUT spammed in case of an error. Our STDOUT is valuable -
our app simply cannot survive a library printing errors to STDOUT. At
the very least, there is a mismatch between implementation and
documentation, right?

Second, I was hoping $aug->set() could be used to add a line to
/etc/fstab like this:

$aug->set('/files/etc/fstab/01', {
    spec => '/dev',
    file => '/foo',
    vfstype => 'none',
    opt => [ 'rw', 'bind' ],
    dump => 0,
    passno => 0
}) or die;

It can't. Is any reason for that? It should be an easy patch, no?
(I'll propose one if there are no objections)

Third, the above set() fails (the subsequent save fails), but it
returns 1 (since it doesn't die) and doesn't set an error:
printf "set error? %s : %s\n", $aug->error(), $aug->error_message();
prints
save error: noerror : No error

A subsequent save:
if (! $aug->save() ) {
    printf "save error: %s : %s\n", $aug->error(), $aug->error_message();
}
prints
save error: noerror : No error

This time, save returns 0, but there is no error information. Long
term, (e.g. if there are many set()-s), this doesn't make it easy to
track down where things went wrong... Isn't it reasonable to expect
that the set() that causes save to fail should fail, or that save()
should give some info about why it didn't return 1?

Am I missing something?

Fourth, is there a repository for perl-augeas ?
https://fedorahosted.org/web/ has java-augeas, ruby-augeas and
python-augeas only.

Peter
-- 
Peter Valdemar Mørch
http://www.morch.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]