Config-Model

 view release on metacpan or  search on metacpan

lib/Config/Model/FuseUI.pm  view on Meta::CPAN

    return 0;
}

## no critic (Subroutines::ProhibitBuiltinHomonyms)
sub rmdir ($name) {
    # return an error numeric, or binary/text string.  (note: 0 means EOF, "0" will
    # give a byte (ascii "0") to the reading program)

    $logger->trace("FuseUI rmdir called on $name");
    my $obj = get_object($name);
    return -ENOENT() unless defined $obj;

    my $type = $obj->get_type;
    return -ENOENT() if ( $type eq 'leaf' or $type eq 'check_list' );

    my $ct       = $obj->container_type;
    my $elt_name = $obj->element_name;
    my $parent   = $obj->parent;

    if ( $ct eq 'list' or $ct eq 'hash' ) {
        my $idx = $obj->index_value;
        $logger->debug("FuseUI rmdir actually deletes $idx");
        $parent->fetch_element($elt_name)->delete($idx);
    }

    # ignore deletion request for other "non deletable" elements

    return 0;
}

## no critic (Subroutines::ProhibitBuiltinHomonyms)
sub unlink ($name) {
    $logger->debug("FuseUI unlink called on $name");
    my $obj  = get_object($name);
    my $type = $obj->get_type;

    return -ENOENT() unless defined $obj;
    return -EISDIR() unless ( $type eq 'leaf' or $type eq 'check_list' );

    my $ct       = $obj->container_type;
    my $elt_name = $obj->element_name;
    my $parent   = $obj->parent;

    if ( $ct eq 'list' or $ct eq 'hash' ) {
        my $idx = $obj->index_value;
        $logger->debug("FuseUI unlink actually deletes $idx");
        $parent->fetch_element($elt_name)->delete($name);
    }

    # ignore deletion request for other "non deletable" elements

    return 0;
}

sub statfs { return 255, 1, 1, 1, 1, 2 }

my @methods = map { ( $_ => __PACKAGE__ . "::$_" ) }
    qw/getattr readdir open read write statfs truncate unlink mkdir rmdir/;

# FIXME: flush release
# maybe also: readlink mknod symlink rename link chmod chown utime

sub run_loop {
    my ( $self, %args ) = @_;
    my $debug = $args{debug} || 0;

    Filesys::Fuse3::main(
        mountpoint => $self->mountpoint,
        @methods,
        debug => $debug || 0,
        threaded => 0,
    );
    return;
}

1;

# ABSTRACT: Fuse virtual file interface for Config::Model

__END__

=pod

=encoding UTF-8

=head1 NAME

Config::Model::FuseUI - Fuse virtual file interface for Config::Model

=head1 VERSION

version 2.162

=head1 SYNOPSIS

 # command line
 mkdir mydir
 cme fusefs popcon -fuse-dir mydir
 ll mydir
 fusermount -u mydir

 # programmatic
 use Config::Model ;
 use Config::Model::FuseUI ;

 my $model = Config::Model -> new; 
 my $root = $model -> instance (root_class_name => "PopCon") -> config_root ; 
 my $ui = Config::Model::FuseUI->new( root => $root, mountpoint => "mydir" ); 
 $ui -> run_loop ;  # blocking call

 # explore mydir in another terminal then umount mydir directory

=head1 DESCRIPTION

This module provides a virtual file system interface for you configuration data. Each possible 
parameter of your configuration file is mapped to a file. 

=head1 Example 

 $ cme fusefs popcon -fuse-dir fused
 Mounting config on fused in background.



( run in 0.596 second using v1.01-cache-2.11-cpan-39bf76dae61 )