line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Maker::Eval; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
58
|
use utf8; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
76
|
|
4
|
9
|
|
|
9
|
|
305
|
use warnings; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
314
|
|
5
|
9
|
|
|
9
|
|
52
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
315
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
87
|
use Carp; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
9341
|
|
8
|
|
|
|
|
|
|
require Config::Maker::Path; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Config::Maker::Eval - Environment to run user-code in Config::Maker |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# In perl-code in metaconfig, config or template |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Get($path) |
19
|
|
|
|
|
|
|
Get($path, $default) |
20
|
|
|
|
|
|
|
Get1($path) |
21
|
|
|
|
|
|
|
Get1($path, $default) |
22
|
|
|
|
|
|
|
Value($path_or_option) |
23
|
|
|
|
|
|
|
Type($path_or_option) |
24
|
|
|
|
|
|
|
Exists($path) |
25
|
|
|
|
|
|
|
Unique($path) |
26
|
|
|
|
|
|
|
One($path) |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
All user code executed by Config::Maker, whether read from metaconfig, config |
31
|
|
|
|
|
|
|
or template, is executed in Config::Maker::Eval package. In that package, |
32
|
|
|
|
|
|
|
following convenience functions are available. Note, that when relative path is |
33
|
|
|
|
|
|
|
specified to any of them, it is resolved relative to the current topic ($_). |
34
|
|
|
|
|
|
|
Thus it must contain a config element. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over 4 |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item Get(I<$path>, I<[$default]>) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Resolves I<$path> and returns list of results, or the first result in scalar |
41
|
|
|
|
|
|
|
context. If I<$default> is given, and the path does not match, I<$default> is |
42
|
|
|
|
|
|
|
returned. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub Get { |
47
|
13
|
|
|
13
|
1
|
29
|
my $path = shift; |
48
|
13
|
|
|
|
|
68
|
$path = Config::Maker::Path->make($path); |
49
|
13
|
|
|
|
|
79
|
my $res = $path->find($_); |
50
|
13
|
50
|
|
|
|
76
|
return wantarray ? @_ : $_[0] unless @$res; |
|
|
100
|
|
|
|
|
|
51
|
9
|
50
|
|
|
|
62
|
return wantarray ? @$res : $res->[0]; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item Get1(I<$path>, I<[$default]>) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Resolves path and returns the result. If there is more than one result, or if |
57
|
|
|
|
|
|
|
the path does not match and no default is given, throws an error. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub Get1 { |
62
|
8
|
|
|
8
|
1
|
20
|
my $path = shift; |
63
|
8
|
|
|
|
|
59
|
$path = Config::Maker::Path->make($path); |
64
|
8
|
|
|
|
|
51
|
my $res = $path->find($_); |
65
|
8
|
100
|
|
|
|
35
|
croak "$path should have at most one result" if @$res > 1; |
66
|
7
|
100
|
100
|
|
|
117
|
croak "$path should have a result" unless @$res || @_ == 1; |
67
|
6
|
100
|
|
|
|
72
|
return @$res ? $res->[0] : $_[0]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item Value(I<$path_or_option>) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns value of config element or matching path (exactly one must match). If |
73
|
|
|
|
|
|
|
no arguments given, returns value of $_. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub Value { |
78
|
2
|
50
|
|
2
|
1
|
10
|
my $arg = (@_ ? $_[0] : $_); |
79
|
2
|
100
|
|
|
|
19
|
if(UNIVERSAL::isa($arg, 'Config::Maker::Option')) { |
80
|
1
|
|
|
|
|
10
|
return $arg->{-value}; |
81
|
|
|
|
|
|
|
} else { |
82
|
1
|
|
|
|
|
6
|
return Get1($arg)->{-value}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item Type(I<$path_or_option>) |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns type of config element or matching path (exactly one must match). If |
89
|
|
|
|
|
|
|
no arguments given, returns type of $_. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub Type { |
94
|
2
|
50
|
|
2
|
1
|
11
|
my $arg = (@_ ? $_[0] : $_); |
95
|
2
|
100
|
|
|
|
12
|
if(UNIVERSAL::isa($arg, 'Config::Maker::Option')) { |
96
|
1
|
|
|
|
|
14
|
return $arg->{-type}; |
97
|
|
|
|
|
|
|
} else { |
98
|
1
|
|
|
|
|
4
|
return Get1($arg)->{-type}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item Exists(I<$path>) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns true iff I<$path> matches at least one config element. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub Exists { |
109
|
3
|
|
|
3
|
1
|
15
|
my @res = Get($_[0]); |
110
|
3
|
|
|
|
|
16
|
return @res > 0; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item Unique(I<$path>) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Returns true iff I<$path> matches at most one config element. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub Unique { |
120
|
3
|
|
|
3
|
1
|
14
|
my @res = Get($_[0]); |
121
|
3
|
|
|
|
|
16
|
return @res <= 1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item One(I<$path>) |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns true iff I<$path> matches exactly one config element. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub One { |
131
|
3
|
|
|
3
|
1
|
10
|
my @res = Get($_[0]); |
132
|
3
|
|
|
|
|
11
|
return @res == 1; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Jan Hudec |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Copyright 2004 Jan Hudec. All rights reserved. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
146
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SEE ALSO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
configit(1), perl(1), Config::Maker(3pm). |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__END__ |