Config-Model

 view release on metacpan or  search on metacpan

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

             warp => {
                 follow => {
                     # this points to the warp master
                     c => '- country'
                 },
                 rules => [
                      {
                          when => '$c eq "US"',
                          apply => { default => 'NTSC' }
                      },
                      {
                          when => '$c eq "France"',
                          apply => { default => 'SECAM' }
                      },
                      {
                          when => '$c eq "Japan"',
                          apply => { default => 'NTSC' }
                      },
                      {
                          when => '$c eq "Europe"',
                          apply => { default => 'PAL' }
                      },
                 ]
             }
         }
     ]
 );

Setting C<country> element to C<US> means that C<tv_standard> has
a default value set to C<NTSC> by the warp mechanism.

Likewise, the warp mechanism enables you to dynamically change the
possible values of an enum element:

 state => {
     type => 'leaf',
     value_type => 'enum', # example is admittedly silly
     warp => {
         follow => {
             c => '- country'
         },
         rules => [
             {
                  when => '$c eq "US"',
                  apply => { choice => ['Kansas', 'Texas' ] }
             },
             {
                  when => '$c eq "Europe"',
                  apply => { choice => ['France', 'Spain' ] }
             },
             {
                  when => '$c eq "Japan"',
                  apply => { choice => ['Honshu', 'Hokkaido' ] }
             }
         ]
     }
 }

=head2 Cascaded warping

Warping value can be cascaded: C<A> can be warped by C<B> which can be
warped by C<C>. But this feature should be avoided since it can lead
to a model very hard to debug. Bear in mind that:

=over

=item *

Warp loops are not detected and end up in "deep recursion
subroutine" failures.

=item *

avoid "diamond" shaped warp dependencies: the results depends on the
order of the warp algorithm which can be unpredictable in this case

=item *

The keys declared in the warp rules (C<US>, C<Europe> and C<Japan> in
the example above) cannot be checked at start time against the warp
master C<Value>. So a wrong warp rule key is silently ignored
during start up and fails at run time.

=back

=head1 Value Reference

To set up an enumerated value where the possible choice depends on the
key of a L<Config::Model::AnyId> object, you must:

=over

=item *

Set C<value_type> to C<reference>.

=item *

Specify the C<refer_to> or C<computed_refer_to> parameter.
See L<refer_to parameter|Config::Model::IdElementReference/"Config class parameters">.

=back

In this case, a C<IdElementReference> object is created to handle the
relation between this value object and the referred Id. See
L<Config::Model::IdElementReference> for details.

=head1 Introspection methods

The following methods returns the current value of the parameter of
the value object (as declared in the model unless they were warped):

=over

=item min

=item max

=item mandatory

=item choice



( run in 0.893 second using v1.01-cache-2.11-cpan-140bd7fdf52 )