File Coverage

blib/lib/App/Cme/Command/fusefs.pm
Criterion Covered Total %
statement 17 47 36.1
branch 0 8 0.0
condition 0 3 0.0
subroutine 6 11 54.5
pod 5 5 100.0
total 28 74 37.8


line stmt bran cond sub pod time code
1             #
2             # This file is part of App-Cme
3             #
4             # This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             # ABSTRACT: Edit the configuration of an application with fuse
11              
12             $App::Cme::Command::fusefs::VERSION = '1.038';
13             use strict;
14 1     1   586 use warnings;
  1         2  
  1         25  
15 1     1   4 use 5.10.1;
  1         2  
  1         19  
16 1     1   18  
  1         4  
17             use App::Cme -command ;
18 1     1   5  
  1         2  
  1         6  
19             use base qw/App::Cme::Common/;
20 1     1   300  
  1         2  
  1         75  
21             use Config::Model::ObjTreeScanner;
22 1     1   5  
  1         1  
  1         395  
23             my ($self, $opt, $args) = @_;
24             $self->check_unknown_args($args);
25 0     0 1   $self->process_args($opt,$args);
26 0            
27 0           my $has_fuse = eval { require Config::Model::FuseUI; 1; };
28              
29 0           die "could not load Config::Model::FuseUI. Is Fuse installed ?\n"
  0            
  0            
30             unless $has_fuse;
31 0 0          
32             my $fd = $opt->{fuse_dir};
33             die "Directory $fd does not exists\n" unless -d $fd;
34 0            
35 0 0         return;
36             }
37 0            
38             my ( $class, $app ) = @_;
39             return (
40             [
41 0     0 1   "fuse-dir=s" => "Directory where the virtual file system will be mounted",
42             {required => 1}
43             ],
44 0           [ "dfuse!" => "debug fuse problems" ],
45             [ "dir-char=s" => "string to replace '/' in configuration parameter names"],
46             [ "backup:s" => "Create a backup of configuration files before saving." ],
47             $class->cme_global_options,
48             );
49             }
50              
51             my ($self) = @_;
52             my $desc = $self->SUPER::usage_desc; # "%c COMMAND %o"
53             return "$desc [application] [file ] -fuse-dir xxx [ -dir-char x ] ";
54             }
55 0     0 1    
56 0           my ($self) = @_;
57 0           return $self->get_documentation;
58             }
59              
60             my ($self, $opt, $args) = @_;
61 0     0 1    
62 0           my ($model, $inst, $root) = $self->init_cme($opt,$args);
63              
64             my @extra;
65             if (my $dc = $opt->{dir_char}) {
66 0     0 1   push @extra, dir_char_mockup => $dc;
67             }
68 0            
69             my $fuse_dir = $opt->{fuse_dir};
70 0           print "Mounting config on $fuse_dir in background.\n",
71 0 0         "Use command 'fusermount -u $fuse_dir' to unmount\n";
72 0            
73             my $ui = Config::Model::FuseUI->new(
74             root => $root,
75 0           mountpoint => $fuse_dir,
76 0           @extra,
77             );
78              
79 0            
80             # now fork
81             my $pid = fork;
82              
83             if ( defined $pid and $pid == 0 ) {
84             # child process, just run fuse and wait for exit
85             $ui->run_loop( debug => $opt->{fuse_debug} );
86             $self->save($inst,$opt);
87 0           }
88              
89 0 0 0       # parent process simply exits
90             return;
91 0           }
92 0            
93             1;
94              
95              
96 0           =pod
97              
98             =encoding UTF-8
99              
100             =head1 NAME
101              
102             App::Cme::Command::fusefs - Edit the configuration of an application with fuse
103              
104             =head1 VERSION
105              
106             version 1.038
107              
108             =head1 SYNOPSIS
109              
110             =head1 DESCRIPTION
111              
112             Map the configuration file content to a FUSE virtual file system on a
113             directory specified with option C<-fuse-dir>. Modifications done in
114             the fuse file system are saved to the configuration file when
115             C<< fusermount -u <mounted_fuse_dir> >> is run.
116              
117             =head1 Common options
118              
119             See L<cme/"Global Options">.
120              
121             =head1 options
122              
123             =over
124              
125             =item -fuse-dir
126              
127             Mandatory. Directory where the virtual file system will be mounted.
128              
129             =item -dfuse
130              
131             Use this option to debug fuse problems.
132              
133             =item -dir-char
134              
135             Fuse will fail if an element name or key name contains '/'. You can specify a
136             substitution string to replace '/' in the fused dir. Default is C<< <slash> >>.
137              
138             =back
139              
140             =head1 SEE ALSO
141              
142             L<cme>
143              
144             =head1 AUTHOR
145              
146             Dominique Dumont
147              
148             =head1 COPYRIGHT AND LICENSE
149              
150             This software is Copyright (c) 2014-2022 by Dominique Dumont <ddumont@cpan.org>.
151              
152             This is free software, licensed under:
153              
154             The GNU Lesser General Public License, Version 2.1, February 1999
155              
156             =cut