.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Class::Mix 3pm" .TH Class::Mix 3pm "2015-06-08" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Class::Mix \- dynamic class mixing .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Class::Mix qw(mix_class); \& \& $foobar_object = mix_class("Foo", "Bar")\->new; \& $digest_class = mix_class("Foo", "Bar", {prefix=>"Digest::"}); \& \& use Class::Mix qw(genpkg); \& \& $package = genpkg; \& $package = genpkg("Digest::Foo::"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The \f(CW\*(C`mix_class\*(C'\fR function provided by this module dynamically generates `anonymous' classes with specified inheritance. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .IP "mix_class(\s-1ITEMS ...\s0)" 4 .IX Item "mix_class(ITEMS ...)" This function is used to dynamically generate `anonymous' classes by mixing pre-existing classes. This is useful where an incomplete class requires use of a mixin in order to become instantiable, several suitable mixins are available, and it is desired to make the choice between mixins at runtime. .Sp Each \fI\s-1ITEM\s0\fR in the argument list is either the name of a class to inherit from (a parent class) or a reference to a hash of options. The \f(CW@ISA\fR list of the mixture class is set to the list of parent class names, in the order supplied. The options that may be supplied are: .RS 4 .IP "\fBmro\fR" 4 .IX Item "mro" Specifies the desired method resolution order (\s-1MRO\s0) of the mixture class. See mro for details of the valid values and the default determined by Perl. Typically, this should be set to \fBc3\fR if mixing into an existing C3\-based class hierarchy. .IP "\fBprefix\fR" 4 .IX Item "prefix" Specifies where the resulting package will go. May be \f(CW\*(C`undef\*(C'\fR to indicate that the caller doesn't care (which is the default state). Otherwise it must be either the empty string (to create a top-level package) or a bareword followed by \*(L"::\*(R" (to create a package under that name). For example, \*(L"Digest::\*(R" could be specified to ensure that the resulting package has a name starting with \*(L"Digest::\*(R", so that \f(CW\*(C`Digest\->new\*(C'\fR will accept it as the name of a message digest algorithm. .RE .RS 4 .Sp The function generates a class of the form described by the arguments, and returns its name. The same class will be returned by repeated invocations with the same parent class list and options. The returned name may be used to call a constructor or other class methods of the mixed class. .Sp A class name must be returned because there is no such thing as an anonymous class in Perl. Classes are referenced by name. The names that are generated by this function are unique and insignificant. See \f(CW\*(C`genpkg\*(C'\fR below for more information. .Sp If fewer than two classes to inherit from are specified, the function tries to avoid generating a separate class for the mixture. If only one parent class is specified then that class may be returned, and if no parent classes are specified then \f(CW\*(C`UNIVERSAL\*(C'\fR may be returned. This provides the desired inheritance without creating superfluous classes. These special cases only apply if the options are compatible with the pre-existing class. .Sp This function relies on the classes it returns remaining unmodified in order to be returned by future invocations. If you want to modify your dynamically-generated `anonymous' classes, use \f(CW\*(C`genpkg\*(C'\fR (below). .RE .IP "genpkg([\s-1PREFIX\s0])" 4 .IX Item "genpkg([PREFIX])" This function selects and returns a package name that has not been previously used. The name returned is an ordinary bareword-form package name, and can be used as the second argument to \f(CW\*(C`bless\*(C'\fR and in all other ways that package names are used. The package is initially empty. .Sp The package names returned by this function are of a type that should not be used as ordinary fixed module names. However, it is not possible to entirely prevent a clash. This function checks that the package name it is about to return has not already been used, and will avoid returning such names, but it cannot guarantee that a later-loaded module will not create a clash. .Sp \&\s-1PREFIX,\s0 if present, specifies where the resulting package will go. It must be either the empty string (to create a top-level package) or a bareword followed by \*(L"::\*(R" (to create a package under that name). For example, \*(L"Digest::\*(R" could be specified to ensure that the resulting package has a name starting with \*(L"Digest::\*(R", so that \f(CW\*(C`Digest\->new\*(C'\fR will accept it as the name of a message digest algorithm. If the \s-1PREFIX\s0 is not supplied, the caller is not expressing any preference. .SH "SEE ALSO" .IX Header "SEE ALSO" Class::Generate, mro .SH "AUTHOR" .IX Header "AUTHOR" Andrew Main (Zefram) .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2004, 2006, 2009, 2010, 2011 Andrew Main (Zefram) .SH "LICENSE" .IX Header "LICENSE" This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.