Config-Augeas-Exporter
view release on metacpan or search on metacpan
lib/Config/Augeas/Exporter.pm view on Meta::CPAN
}
return 0;
}
sub sanitize_path {
my ($path) = @_;
return unless ($path);
# Sanitize path for augeas requests
$path =~ s|(?<=[^\\]) |\\ |g;
return $path;
}
sub is_file {
my ($self, $path) = @_;
my $aug_path = "/augeas${path}/path";
my $aug = $self->{aug};
my $count = $aug->count_match($aug_path);
# Not a file if there is no path subnode
return 0 if ($count == 0);
# Check that the subnode has the right value
return 1 if ($aug->get($aug_path) eq $path);
# Otherwise it's not a file
return 0;
}
sub is_dir {
my ($self, $path) = @_;
my $aug_path = "/augeas${path}";
my $aug = $self->{aug};
my $count = $aug->count_match($aug_path);
my $value = $aug->get($aug_path);
# A directory is not a file
# but its path must exist in /augeas
# and have no value associated to it
return 1 if (!$self->is_file($path) && $count == 1
&& !defined($value));
# Otherwise it's not a directory
return 0;
}
sub stat_to_xml {
my ($self, $path) = @_;
my $aug_root = $self->{aug_root};
my %stat;
($stat{dev}, $stat{ino}, $stat{mode}, $stat{nlink},
$stat{uid}, $stat{gid}, $stat{rdev}, $stat{size},
$stat{atime}, $stat{mtime}, $stat{ctime},
$stat{blksize}, $stat{blocks}) = stat("${aug_root}${path}");
my $stat_elem = XML::LibXML::Element->new('stat');
for my $k (keys(%stat)) {
$stat_elem->setAttribute($k, $stat{$k});
}
return $stat_elem;
}
__END__
=head1 SEE ALSO
=over
=item *
L<Config::Augeas> : The Config::Augeas module
=item *
http://augeas.net/ : The Augeas project page
=back
=head1 AUTHOR
RaphaE<euml>l Pinson, E<lt>raphink at cpan dot orgE<gt>
=head1 CONTRIBUTING
This module is developed on Launchpad at:
L<https://launchpad.net/config-augeas-exporter>
Feel free to fork the repository and submit pull requests
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 by RaphaE<euml>l Pinson
This library is free software; you can redistribute it and/or modify
it under the LGPL terms.
=cut
( run in 1.509 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )