1XML::Grove::Factory(3)User Contributed Perl DocumentationXML::Grove::Factory(3)
2
3
4

NAME

6       XML::Grove::Factory - simplify creation of XML::Grove objects
7

SYNOPSIS

9        use XML::Grove::Factory;
10
11        ### An object that creates Grove objects directly
12        my $gf = XML::Grove::Factory->grove_factory;
13
14        $grove = $gf->document( CONTENTS );
15        $element = $gf->element( $name, { ATTRIBUTES }, CONTENTS );
16        $pi = $gf->pi( $target, $data );
17        $comment = $gf->comment( $data );
18
19        ### An object that creates elements by method name
20        my $ef = XML::Grove::Factory->element_factory();
21
22        $element = $ef->NAME( { ATTRIBUTES }, CONTENTS);
23
24        ### Similar to `element_factory', but creates functions in the
25        ### current package
26        XML::Grove::Factory->element_functions( PREFIX, ELEMENTS );
27
28        $element = NAME( { ATTRIBUTES }, CONTENTS );
29

DESCRIPTION

31       "XML::Grove::Factory" provides objects or defines functions that let
32       you simply and quickly create the most commonly used XML::Grove
33       objects.  "XML::Grove::Factory" supports three types of object
34       creation.  The first type is to create raw XML::Grove objects.  The
35       second type creates XML elements by element name.  The third type is
36       like the second, but defines local functions for you to call instead of
37       using an object, which might save typing in some cases.
38
39       The three types of factories can be mixed.  For example, you can use
40       local functions for all element names that don't conflict with your own
41       sub names or contain special characters, and then use a
42       `"grove_factory()"' object for those elements that do conflict.
43
44       In the examples that follow, each example is creating an XML instance
45       similar to the following, assuming it's pretty printed:
46
47           <?xml version="1.0"?>
48           <HTML>
49             <HEAD>
50               <TITLE>Some Title</TITLE>
51             </HEAD>
52             <BODY bgcolor="#FFFFFF">
53               <P>A paragraph.</P>
54             </BODY>
55           </HTML>
56

GROVE FACTORY

58       $gf = XML::Grove::Factory->grove_factory()
59           Creates a new grove factory object that creates raw XML::Grove
60           objects.
61
62       $gf->document( CONTENTS );
63           Creates an XML::Grove::Document object.  CONTENTS may contain
64           processing instructions, strings containing only whitespace
65           characters, and a single element object (but note that there is no
66           checking).  Strings are converted to XML::Grove::Characters
67           objects.
68
69       $gf->element($name, CONTENTS);
70       $gf->element($name, { ATTRIBUTES }, CONTENTS);
71           Creates an XML::Grove::Element object with the name `$name'.  If
72           the argument following `$name' is an anonymous hash, ATTRIBUTES,
73           then they will be copied to the elements attributes.  CONTENTS will
74           be stored in the element's content (note that there is no validity
75           checking).  Strings in CONTENTS are converted to
76           XML::Grove::Characters objects.
77
78       $gf->pi( TARGET, DATA)
79       $gf->pi( DATA )
80           Create an XML::Grove::PI object with TARGET and DATA.
81
82       $gf->comment( DATA )
83           Create an XML::Grove::Comment object with DATA.
84
85   GROVE FACTORY EXAMPLE
86        use XML::Grove::Factory;
87
88        $gf = XML::Grove::Factory->grove_factory;
89
90        $element =
91          $gf->element('HTML',
92            $gf->element('HEAD',
93              $gf->element('TITLE', 'Some Title')),
94            $gf->element('BODY', { bgcolor => '#FFFFFF' },
95              $gf->element('P', 'A paragraph.')));
96

ELEMENT FACTORY

98       $ef = XML::Grove::Factory->element_factory()
99           Creates a new element factory object for creating elements.
100           `"element_factory()"' objects work by creating an element for any
101           name used to call the object.
102
103       $ef->NAME( CONTENTS )
104       $ef->NAME( { ATTRIBUTES }, CONTENTS)
105           Creates an XML::Grove::Element object with the given NAME,
106           ATTRIBUTES, and CONTENTS.  The hash containing ATTRIBUTES is
107           optional if this element doesn't need attributes.  Strings in
108           CONTENTS are converted to XML::Grove::Characters objects.
109
110   ELEMENT FACTORY EXAMPLE
111        use XML::Grove::Factory;
112
113        $ef = XML::Grove::Factory->element_factory();
114
115        $element =
116          $ef->HTML(
117            $ef->HEAD(
118              $ef->TITLE('Some Title')),
119            $ef->BODY({ bgcolor => '#FFFFFF' },
120              $ef->P('A paragraph.')));
121

ELEMENT FUNCTIONS

123       XML::Grove::Factory->element_functions (PREFIX, ELEMENTS)
124           Creates functions in the current package for creating elements with
125           the names provided in the list ELEMENTS.  PREFIX will be prepended
126           to every function name, or PREFIX can be an empty string ('') if
127           you're confident that there won't be any conflicts with functions
128           in your package.
129
130       NAME( CONTENTS )
131       NAME( { ATTRIBUTES }, CONTENTS )
132       PREFIXNAME( CONTENTS )
133       PREFIXNAME( { ATTRIBUTES }, CONTENTS )
134           Functions created for `"NAME"' or `"PREFIXNAME"' can be called to
135           create XML::Grove::Element objects with the given NAME, ATTRIBUTES,
136           and CONTENT.  The hash containing ATTRIBUTES is optional if this
137           element doesn't need attributes.  Strings in CONTENT are converted
138           to XML::Grove::Characters objects.
139
140   ELEMENT FACTORY EXAMPLE
141        use XML::Grove::Factory;
142
143        XML::Grove::Factory->element_functions('', qw{ HTML HEAD TITLE BODY P });
144
145        $element =
146          HTML(
147            HEAD(
148              TITLE('Some Title')),
149            BODY({ bgcolor => '#FFFFFF' },
150              P('A paragraph.')));
151

AUTHOR

153       Ken MacLeod, ken@bitsko.slc.ut.us
154
155       Inspired by the HTML::AsSubs module by Gisle Aas.
156

SEE ALSO

158       perl(1), XML::Grove(3).
159
160       Extensible Markup Language (XML) <http://www.w3c.org/XML>
161

POD ERRORS

163       Hey! The above document had some coding errors, which are explained
164       below:
165
166       Around line 307:
167           You forgot a '=back' before '=head2'
168
169
170
171perl v5.30.1                      2020-01-30            XML::Grove::Factory(3)
Impressum