1Package::Generator(3) User Contributed Perl DocumentationPackage::Generator(3)
2
3
4

NAME

6       Package::Generator - generate new packages quickly and easily
7

VERSION

9       version 1.106
10

SYNOPSIS

12           use Package::Generator;
13
14           my $package = Package::Generator->new_package;
15           ...
16

DESCRIPTION

18       This module lets you quickly and easily construct new packages.  It
19       gives them unused names and sets up their package data, if provided.
20

INTERFACE

22   new_package
23         my $package = Package::Generator->new_package(\%arg);
24
25       This returns the newly generated package.  It can be called with no
26       arguments, in which case it just returns the name of a pristene
27       package.  The "base" argument can be provided to generate the package
28       under an existing namespace.  A "make_unique" argument can also be
29       provided; it must be a coderef which will be passed the base package
30       name and returns a unique package name under the base name.
31
32       A "data" argument may be passed as a reference to an array of pairs.
33       These pairs will be used to set up the data in the generated package.
34       For example, the following call will create a package with a $foo set
35       to 1 and a @foo set to the first ten counting numbers.
36
37         my $package = Package::Generator->new_package({
38           data => [
39             foo => 1,
40             foo => [ 1 .. 10 ],
41           ]
42         });
43
44       For convenience, "isa" and "version" arguments may be passed to
45       "new_package".  They will set up @ISA, $VERSION, or &VERSION, as
46       appropriate.  If a single scalar value is passed as the "isa" argument,
47       it will be used as the only value to assign to @ISA.  (That is, it will
48       not cause $ISA to be assigned;  that wouldn't be very helpful.)
49
50   assign_symbols
51         Package::Generator->assign_symbols($package, \@key_value_pairs);
52
53       This routine is used by "new_package" to set up the data in a package.
54
55   package_exists
56         ... if Package::Generator->package_exists($package);
57
58       This method returns true if something has already created a symbol
59       table for the named package.  This is equivalent to:
60
61         ... if defined *{$package . '::'};
62
63       It's just a little less voodoo-y.
64

AUTHOR

66       Ricardo SIGNES <rjbs@cpan.org>
67
69       This software is copyright (c) 2005 by Ricardo SIGNES.
70
71       This is free software; you can redistribute it and/or modify it under
72       the same terms as the Perl 5 programming language system itself.
73
74
75
76perl v5.38.0                      2023-07-21             Package::Generator(3)
Impressum