File: recursive_warp_value.t

package info (click to toggle)
libconfig-model-perl 2.021-3%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,104 kB
  • sloc: perl: 20,550; makefile: 11
file content (125 lines) | stat: -rw-r--r-- 3,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- cperl -*-
# $Author$
# $Date$
# $Revision$

use warnings FATAL => qw(all);

use ExtUtils::testlib;
use Test::More tests => 21;
use Test::Memory::Cycle;
use Config::Model ;

use strict;

my $arg = shift || '';

my $trace = $arg =~ /t/ ? 1 : 0 ;
$::debug            = 1 if $arg =~ /d/;
Config::Model::Exception::Any->Trace(1) if $arg =~ /e/;

use Log::Log4perl qw(:easy) ;
Log::Log4perl->easy_init($arg =~ /l/ ? $TRACE: $WARN);

ok(1,"Compilation done");

# minimal set up to get things working
my $model = Config::Model->new(legacy => 'ignore',) ;
$model ->create_config_class 
  (
   name => 'Master',
   'element'
   => [
       macro => { type => 'leaf',
		  value_type => 'enum',
		  choice     => [qw/A B C/]
		},
       m1 =>  { type => 'leaf',
		value_type => 'string',
		warp       => {
			       follow => '- macro',
			       rules => [ A => { default => 'm1_A' },
					  B => { default => 'm1_B' },
					  C => { default => 'm1_C' }
					]
			      }
	      },
       compute => { type => 'leaf',
		    value_type => 'string',
		    compute    => [ 'macro is $m, my slot is &slot', 
				    'm' => '!  macro' ]
		  },
       # second level warp (kinda recursive and scary ...)
       m2a => { type => 'leaf',
		value_type => 'string',
		warp       => {
			       follow => '- m1',
			       rules => [ m1_A => { default => 'm2a_A' },
					  m1_B => { default => 'm2a_B' },
					  m1_C => { default => 'm2a_C' }
					]
			      }
	      },
       # second level warp (kinda recursive and scary ...)
       m2b => { type => 'leaf', 
		value_type => 'string',
		warp       => {
			       follow => '- m1',
			       rules => [ m1_A => { default => 'm2b_A' },
					  m1_B => { default => 'm2b_B' },
					  m1_C => { default => 'm2b_C' }
					]
			      }
	      },
       e1 =>  { type => 'leaf',
		value_type => 'enum',
		'warp'
		=> {
		    follow => '- macro',
		    'rules'
		    => [
			A => { choice => [qw/e1_A e1_B/], default => 'e1_A' },
			B => { choice => [qw/e1_B e1_C/], default => 'e1_B' },
			C => { choice => [qw/e1_C e1_D/], default => 'e1_C' }
		       ]
		   }
	      },
       e2 =>  { type => 'leaf',
		value_type => 'string',
		warp       => {
			       follow => '- e1',
			       rules => [ e1_A => { default => 'e2_A' },
					  e1_B => { default => 'e2_B' },
					  e1_C => { default => 'e2_C' }
					]
			      }
	      },
      ],
   );

my $inst = $model->instance (root_class_name => 'Master', 
			     instance_name => 'test1');
ok($inst,"created dummy instance") ;

my $root = $inst -> config_root ;


foreach my $mv (qw/A B C/) {
    ok( $root->fetch_element('macro')->store($mv) ,
	"Set macro to $mv");

    foreach my $element (qw/m1 m2a m2b/) {
        is( $root->fetch_element($element)->fetch(),
	    $element . '_' . $mv,
	    "Reading Master element $element");
    }

    foreach my $element (qw/e1 e2/) {
        is( $root->fetch_element($element)->fetch(),
	    $element . '_' . $mv ,
	    "Reading Master element $element");
    }

}

memory_cycle_ok($model);