Config-Model

 view release on metacpan or  search on metacpan

lib/Config/Model/Manual/ModelCreationAdvanced.pod  view on Meta::CPAN

   level => 'hidden',             # by default, is hidden from user
   warp => {                      # instructions to show bind_address
     follow => {                  # specify what does trigger the change
        gp => '- - GatewayPorts'  # gp: go to 2 levels above in tree ('- -') and
                                  #     fetch GatewayPorts value
     },
     rules => [                   # specify how to apply the change triggered by gp
       '$gp' => {                 # apply change when $gp is true
           level => 'normal'      # set level to normal (instead of 'hidden'). This change
                                  #     will show this parameter in the UI
       }
     ]
   },
 },

=head2 warped node

Sometimes, warping a value line by line is not practical. For
instance, in C</etc/fstab> the mount options of a file system change
drastically from one file system to another. In this case, it's better
to swap a configuration class with another.

For instance, swap C<vfat> mount options with C<ext3> mount options
when a file system is changed from C<vfat> to C<ext3>.

Here's how this can be done. First declare the C<fstype> parameter:

 fs_vfstype => {
   type => 'leaf',
   mandatory => 1,
   value_type => 'enum',
   choice => [ 'auto', 'davfs', 'vfat', 'ext2', 'ext3', ] , # etc ...
 }

Then declare C<mntopts> as a B<warped_node> (not a simple C<node>))
that uses C<fs_vfstype> to swap one config class with another:

 fs_mntopts => {
   type => 'warped_node', # a shape-shifting node
   follow => {
     f1 => '- fs_vfstype' , # use fs_vfstype as a trigger
   },
   rules => [
     # condition     => effect: config class to swap in

     "$f1 eq 'proc'" => { config_class_name => 'Fstab::CommonOptions' },
     "$f1 eq 'auto'" => { config_class_name => 'Fstab::CommonOptions' },
     "$f1 eq 'vfat'" => { config_class_name => 'Fstab::CommonOptions' },
     "$f1 eq 'swap'" => { config_class_name => 'Fstab::SwapOptions'   },
     "$f1 eq 'ext3'" => { config_class_name => 'Fstab::Ext3FsOpt'     },
     # etc ...
   ]
  }

=head1 References

=head1 Computation and migrations

=head2 Cascaded warp

Config::Model also supports cascaded warps: A warped value is
dependent on another value which is itself a warped value.

=head1 Feedback welcome

Feel free to send comments and suggestion about this page at

 config-model-users at lists dot sourceforge dot net.

=head1 AUTHORS

Dominique Dumont <ddumont at cpan.org>

=head1 AUTHOR

Dominique Dumont

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2005-2022 by Dominique Dumont.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999

=cut



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