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.200012
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 sequence_class
23 This attribute stores the name of the class to be used for the
24 assembler's sequence. It defaults to Config::MVP::Sequence.
25
26 section_class
27 This attribute stores the name of the class to be used for sections
28 created by the assembler. It defaults to Config::MVP::Section.
29
30 sequence
31 This is the sequence that the assembler is assembling. It defaults to
32 a new instance of the assembler's "sequence_class".
33
35 begin_section
36 $assembler->begin_section($package_moniker, $name);
37
38 $assembler->begin_section($package_moniker);
39
40 $assembler->begin_section( \$package );
41
42 This method tells the assembler that it should begin work on a new
43 section with the given identifier. If it is already working on a
44 section, an error will be raised. See "change_section" for a method to
45 begin a new section, ending the current one if needed.
46
47 The package moniker is expanded by the "expand_package" method. The
48 name, if not given, defaults to the package moniker. These data are
49 used to create a new section and the section is added to the end of the
50 sequence. If the package argument is a reference, it is used as the
51 literal value for the package, and no expansion is performed. If it is
52 a reference to undef, a section with no package is created.
53
54 end_section
55 $assembler->end_section;
56
57 This ends the current section. If there is no current section, an
58 exception is raised.
59
60 change_section
61 $assembler->change_section($package_moniker, $name);
62
63 $assembler->change_section($package_moniker);
64
65 This method calls "begin_section", first calling "end_section" if
66 needed.
67
68 add_value
69 $assembler->add_value( $name => $value );
70
71 This method tells the assembler that it has encountered a named value
72 and should add it to the current section. If there is no current
73 section, an exception is raised. (If this is not the first time we've
74 seen the name in the section and it's not a multivalue property, the
75 section class will raise an exception on its own.)
76
77 expand_package
78 This method is passed a short identifier for a package and is expected
79 to return the full name of the module to load and package to
80 interrogate. By default it simply returns the name it was passed,
81 meaning that package names must be given whole to the "change_section"
82 method.
83
84 current_section
85 This returns the section object onto which the assembler is currently
86 adding values. If no section has yet been created, this method will
87 return false.
88
90 my $assembler = Config::MVP::Assembler->new;
91
92 # Maybe you want a starting section:
93 my $starting_section = $assembler->section_class->new({ name => '_' });
94 $assembler->sequence->add_section($section_starting);
95
96 # We'll add some values, which will go to the starting section:
97 $assembler->add_value(x => 10);
98 $assembler->add_value(y => 20);
99
100 # Change to a new section...
101 $assembler->change_section($moniker);
102
103 # ...and add values to that section.
104 $assembler->add_value(x => 100);
105 $assembler->add_value(y => 200);
106
107 The code above creates an assembler and populates it step by step. In
108 the end, to get values, you could do something like this:
109
110 my @output;
111
112 for my $section ($assembler->sequence->sections) {
113 push @output, [ $section->name, $section->package, $section->payload ];
114 }
115
116 When changing sections, the given section "moniker" is used for the new
117 section name. The result of passing that moniker to the assembler's
118 "expand_package" method is used as the section's package name. (By
119 default, this method does nothing.) The new section's
120 "multivalue_args" and "aliases" are determined by calling the
121 "mvp_multivalue_args" and "mvp_aliases" methods on the package.
122
124 Ricardo Signes <rjbs@cpan.org>
125
127 This software is copyright (c) 2021 by Ricardo Signes.
128
129 This is free software; you can redistribute it and/or modify it under
130 the same terms as the Perl 5 programming language system itself.
131
132
133
134perl v5.32.1 2021-01-27 Config::MVP::Assembler(3)