1Config::MVP::Assembler(U3s)er Contributed Perl DocumentatCioonnfig::MVP::Assembler(3)
2
3
4
6 Config::MVP::Assembler - multivalue-property config-loading state
7 machine
8
10 version 2.200013
11
13 First, you should probably read the example of using Config::MVP. If
14 you already know how it works, keep going.
15
16 Config::MVP::Assembler is a helper for constructing a
17 Config::MVP::Sequence object. It's a very simple state machine that
18 lets you signal what kind of events you've encountered while reading
19 configuration.
20
22 This module should work on any version of perl still receiving updates
23 from the Perl 5 Porters. This means it should work on any version of
24 perl released in the last two to three years. (That is, if the most
25 recently released version is v5.40, then this module should work on
26 both v5.40 and v5.38.)
27
28 Although it may work on older versions of perl, no guarantee is made
29 that the minimum required version will not be increased. The version
30 may be increased for any reason, and there is no promise that patches
31 will be accepted to lower the minimum required perl.
32
34 sequence_class
35 This attribute stores the name of the class to be used for the
36 assembler's sequence. It defaults to Config::MVP::Sequence.
37
38 section_class
39 This attribute stores the name of the class to be used for sections
40 created by the assembler. It defaults to Config::MVP::Section.
41
42 sequence
43 This is the sequence that the assembler is assembling. It defaults to
44 a new instance of the assembler's "sequence_class".
45
47 begin_section
48 $assembler->begin_section($package_moniker, $name);
49
50 $assembler->begin_section($package_moniker);
51
52 $assembler->begin_section( \$package );
53
54 This method tells the assembler that it should begin work on a new
55 section with the given identifier. If it is already working on a
56 section, an error will be raised. See "change_section" for a method to
57 begin a new section, ending the current one if needed.
58
59 The package moniker is expanded by the "expand_package" method. The
60 name, if not given, defaults to the package moniker. These data are
61 used to create a new section and the section is added to the end of the
62 sequence. If the package argument is a reference, it is used as the
63 literal value for the package, and no expansion is performed. If it is
64 a reference to undef, a section with no package is created.
65
66 end_section
67 $assembler->end_section;
68
69 This ends the current section. If there is no current section, an
70 exception is raised.
71
72 change_section
73 $assembler->change_section($package_moniker, $name);
74
75 $assembler->change_section($package_moniker);
76
77 This method calls "begin_section", first calling "end_section" if
78 needed.
79
80 add_value
81 $assembler->add_value( $name => $value );
82
83 This method tells the assembler that it has encountered a named value
84 and should add it to the current section. If there is no current
85 section, an exception is raised. (If this is not the first time we've
86 seen the name in the section and it's not a multivalue property, the
87 section class will raise an exception on its own.)
88
89 expand_package
90 This method is passed a short identifier for a package and is expected
91 to return the full name of the module to load and package to
92 interrogate. By default it simply returns the name it was passed,
93 meaning that package names must be given whole to the "change_section"
94 method.
95
96 current_section
97 This returns the section object onto which the assembler is currently
98 adding values. If no section has yet been created, this method will
99 return false.
100
102 my $assembler = Config::MVP::Assembler->new;
103
104 # Maybe you want a starting section:
105 my $starting_section = $assembler->section_class->new({ name => '_' });
106 $assembler->sequence->add_section($section_starting);
107
108 # We'll add some values, which will go to the starting section:
109 $assembler->add_value(x => 10);
110 $assembler->add_value(y => 20);
111
112 # Change to a new section...
113 $assembler->change_section($moniker);
114
115 # ...and add values to that section.
116 $assembler->add_value(x => 100);
117 $assembler->add_value(y => 200);
118
119 The code above creates an assembler and populates it step by step. In
120 the end, to get values, you could do something like this:
121
122 my @output;
123
124 for my $section ($assembler->sequence->sections) {
125 push @output, [ $section->name, $section->package, $section->payload ];
126 }
127
128 When changing sections, the given section "moniker" is used for the new
129 section name. The result of passing that moniker to the assembler's
130 "expand_package" method is used as the section's package name. (By
131 default, this method does nothing.) The new section's
132 "multivalue_args" and "aliases" are determined by calling the
133 "mvp_multivalue_args" and "mvp_aliases" methods on the package.
134
136 Ricardo Signes <cpan@semiotic.systems>
137
139 This software is copyright (c) 2022 by Ricardo Signes.
140
141 This is free software; you can redistribute it and/or modify it under
142 the same terms as the Perl 5 programming language system itself.
143
144
145
146perl v5.38.0 2023-07-20 Config::MVP::Assembler(3)