.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" 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 .\" ======================================================================== .\" .IX Title "MakeMethods::Autoload 3pm" .TH MakeMethods::Autoload 3pm "2016-06-10" "perl v5.22.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::MakeMethods::Autoload \- Declare generated subs with AUTOLOAD .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package MyObject; \& use Class::MakeMethods::Autoload \*(AqStandard::Hash::scalar\*(Aq; \& \& package main; \& my $obj = bless {}, \*(AqMyObject\*(Aq; \& \& $obj\->foo("Foozle"); \& print $obj\->foo(); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This package provides a generate-on-demand interface to Class::MakeMethods. .PP When your class uses this package, it imports an \s-1AUTOLOAD\s0 function that resolves missing methods by using Class::MakeMethods to generate and install a standard type of method. .PP You must specify the type of method to be generated by passing a single argument to your use Class::MakeMethods::Autoload statement, which can take any of these forms: .IP "\(bu" 4 A Class::MakeMethods generator name and method type. .Sp Here are three examples: .Sp .Vb 1 \& use Class::MakeMethods::Autoload \*(AqStandard::Hash:scalar\*(Aq; \& \& use Class::MakeMethods::Autoload \*(AqBasic::Universal::no_op\*(Aq; \& \& use Class::MakeMethods::Autoload \& \*(Aq::Class::MakeMethod::Composite::Global:array\*(Aq; .Ve .IP "\(bu" 4 A reference to a subroutine which will be called for each requested function name and which is expected to return the name of the method generator to use. .Sp Here's a contrived example which generates scalar accessors for methods except those with a digit in their name, which are treated as globals. .Sp .Vb 5 \& use Class::MakeMethods::Autoload sub { \& my $name = shift; \& ( $name =~ /\ed/ ) ? \*(AqStandard::Global::scalar\*(Aq \& : \*(AqStandard::Hash::scalar\*(Aq \& }; .Ve .IP "\(bu" 4 A reference to a hash which defines which method type to use based on the name of the requested method. If a key exists which is an exact match for the requested function name, the associated value is used; otherwise, each of the keys is used as a regular expression, and the value of the first one that matches the function name is used. (For regular expression matching, the keys are tested in reverse length order, longest to shortest.) .Sp Here's an example which provides a \fInew()\fR constructor, a \s-1\fIDESTROY\s0()\fR method that does nothing, and a wildcard match that provides scalar accessors for all other Autoloaded methods: .Sp .Vb 5 \& use Class::MakeMethods::Autoload { \& \*(Aqnew\*(Aq => \*(AqStandard::Hash::new\*(Aq, \& \*(Aq.*\*(Aq => \*(AqStandard::Hash::scalar\*(Aq, \& \*(AqDESTROY\*(Aq => \*(AqStandard::Universal::no_op\*(Aq, \& }; .Ve .Sp Here's a more sophisticated example which causes all-upper-case method names to be generated as globals, those with a leading upper-case letter to be generated as inheritable data methods, and others to be normal accessors: .Sp .Vb 7 \& use Class::MakeMethods::Autoload { \& \*(Aqnew\*(Aq => \*(AqStandard::Hash::new\*(Aq, \& \*(Aq.*\*(Aq => \*(AqStandard::Hash::scalar\*(Aq, \& \*(Aq[A\-Z].*\*(Aq => \*(AqStandard::Inheritable::scalar\*(Aq, \& \*(Aq[A\-Z0\-9]+\*(Aq => \*(AqStandard::Global::scalar\*(Aq, \& \*(AqDESTROY\*(Aq => \*(AqStandard::Universal::no_op\*(Aq, \& }; .Ve .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" The following warnings and errors may be produced when using Class::MakeMethods::Attribute to generate methods. (Note that this list does not include run-time messages produced by calling the generated methods, or the standard messages produced by Class::MakeMethods.) .IP "No default method type; can't autoload" 4 .IX Item "No default method type; can't autoload" You must declare a default method type, generally by passing its name to a \f(CW\*(C`use Class::MakeMethods::Autoload\*(C'\fR statement, prior to autoloading any methods. .ie n .IP "Construction of %s method %s failed to produce usable method" 4 .el .IP "Construction of \f(CW%s\fR method \f(CW%s\fR failed to produce usable method" 4 .IX Item "Construction of %s method %s failed to produce usable method" Indicates that Autoload successfully called Class::MakeMethods\->make to generate the requested method, but afterwards was not able to invoke the generated method. You may have selected an incompatible method type, or the method may not have been installed sucesfully. .SH "SEE ALSO" .IX Header "SEE ALSO" See Class::MakeMethods for general information about this distribution. .PP For distribution, installation, support, copyright and license information, see Class::MakeMethods::Docs::ReadMe.