1Class::Mix(3)         User Contributed Perl Documentation        Class::Mix(3)
2
3
4

NAME

6       Class::Mix - dynamic class mixing
7

SYNOPSIS

9               use Class::Mix qw(mix_class);
10
11               $foobar_object = mix_class("Foo", "Bar")->new;
12
13               use Class::Mix qw(genpkg);
14
15               $package = genpkg;
16               $package = genpkg("Digest::Foo::");
17

DESCRIPTION

19       The "mix_class" function provided by this module dynamically generates
20       `anonymous' classes with specified inheritance.
21

FUNCTIONS

23       mix_class(CLASSES ...)
24           This function is used to dynamically generate `anonymous' classes
25           by mixing pre-existing classes.  This is useful where an incomplete
26           class requires use of a mixin in order to become instantiable,
27           several suitable mixins are available, and it is desired to make
28           the choice between mixins at runtime.
29
30           The function takes as its argument list the desired @ISA list of
31           the mixture class to be created; that is, a list of names of
32           classes to inherit from.  It generates a class with the specified
33           inheritance, and returns its name.  The same class will be returned
34           by repeated invocations with the same class list.  The returned
35           name may be used to call a constructor or other class methods of
36           the mixed class.
37
38           A class name must be returned because there is no such thing as an
39           anonymous class in Perl.  Classes are referenced by name.  The
40           names that are generated by this function are unique and
41           insignificant.  See "genpkg" below for more information.
42
43           If fewer than two classes to inherit from are specified, the
44           function does not bother to generate a new class.  If only one
45           class is specified then that class is returned.  If no classes are
46           specified then "UNIVERSAL" is returned.  This provides the desired
47           inheritance without creating superfluous classes.
48
49           This function relies on the classes it returns remaining unmodified
50           in order to be returned by future invocations.  If you want to
51           modify your dynamically-generated `anonymous' classes, use "genpkg"
52           (below).
53
54       genpkg([PREFIX])
55           This function selects and returns a package name that has not been
56           previously used.  The name returned is an ordinary bareword-form
57           package name, and can be used as the second argument to "bless" and
58           in all other ways that package names are used.  The package is
59           initially empty.
60
61           The package names returned by this function are of a type that
62           should not be used as ordinary fixed module names.  However, it is
63           not possible to entirely prevent a clash.  This function checks
64           that the package name it is about to return has not already been
65           used, and will avoid returning such names, but it cannot guarantee
66           that a later-loaded module will not create a clash.
67
68           PREFIX, if present, specifies where the resulting package will go.
69           It must be either the empty string (to create a top-level package)
70           or a bareword followed by "::" (to create a package under that
71           name).  For example, "Digest::" could be specified to ensure that
72           the resulting package has a name starting with "Digest::", so that
73           "Digest->new" will accept it as the name of a message digest
74           algorithm.
75

SEE ALSO

77       Class::Generate
78

AUTHOR

80       Andrew Main (Zefram) <zefram@fysh.org>
81
83       Copyright (C) 2004, 2006, 2009 Andrew Main (Zefram) <zefram@fysh.org>
84

LICENSE

86       This module is free software; you can redistribute it and/or modify it
87       under the same terms as Perl itself.
88
89
90
91perl v5.12.0                      2010-04-30                     Class::Mix(3)
Impressum