1MakeMethods::Autoload(3U)ser Contributed Perl DocumentatiMoankeMethods::Autoload(3)
2
3
4

NAME

6       Class::MakeMethods::Autoload - Declare generated subs with AUTOLOAD
7

SYNOPSIS

9         package MyObject;
10         use Class::MakeMethods::Autoload 'Standard::Hash::scalar';
11
12         package main;
13         my $obj = bless {}, 'MyObject';
14
15         $obj->foo("Foozle");
16         print $obj->foo();
17

DESCRIPTION

19       This package provides a generate-on-demand interface to
20       Class::MakeMethods.
21
22       When your class uses this package, it imports an AUTOLOAD function that
23       resolves missing methods by using Class::MakeMethods to generate and
24       install a standard type of method.
25
26       You must specify the type of method to be generated by passing a single
27       argument to your use Class::MakeMethods::Autoload statement, which can
28       take any of these forms:
29
30       ·   A Class::MakeMethods generator name and method type.
31
32           Here are three examples:
33
34             use Class::MakeMethods::Autoload 'Standard::Hash:scalar';
35
36             use Class::MakeMethods::Autoload 'Basic::Universal::no_op';
37
38             use Class::MakeMethods::Autoload
39                           '::Class::MakeMethod::Composite::Global:array';
40
41       ·   A reference to a subroutine which will be called for each requested
42           function name and which is expected to return the name of the
43           method generator to use.
44
45           Here's a contrived example which generates scalar accessors for
46           methods except those with a digit in their name, which are treated
47           as globals.
48
49             use Class::MakeMethods::Autoload sub {
50               my $name = shift;
51               ( $name =~ /\d/ ) ? 'Standard::Global::scalar'
52                                 : 'Standard::Hash::scalar'
53             };
54
55       ·   A reference to a hash which defines which method type to use based
56           on the name of the requested method. If a key exists which is an
57           exact match for the requested function name, the associated value
58           is used; otherwise, each of the keys is used as a regular
59           expression, and the value of the first one that matches the
60           function name is used. (For regular expression matching, the keys
61           are tested in reverse length order, longest to shortest.)
62
63           Here's an example which provides a new() constructor, a DESTROY()
64           method that does nothing, and a wildcard match that provides scalar
65           accessors for all other Autoloaded methods:
66
67             use Class::MakeMethods::Autoload {
68               'new'     => 'Standard::Hash::new',
69               '.*'      => 'Standard::Hash::scalar',
70               'DESTROY' => 'Standard::Universal::no_op',
71             };
72
73           Here's a more sophisticated example which causes all-upper-case
74           method names to be generated as globals, those with a leading
75           upper-case letter to be generated as inheritable data methods, and
76           others to be normal accessors:
77
78             use Class::MakeMethods::Autoload {
79               'new'     => 'Standard::Hash::new',
80               '.*'      => 'Standard::Hash::scalar',
81               '[A-Z].*' => 'Standard::Inheritable::scalar',
82               '[A-Z0-9]+' => 'Standard::Global::scalar',
83               'DESTROY' => 'Standard::Universal::no_op',
84             };
85

DIAGNOSTICS

87       The following warnings and errors may be produced when using
88       Class::MakeMethods::Attribute to generate methods. (Note that this list
89       does not include run-time messages produced by calling the generated
90       methods, or the standard messages produced by Class::MakeMethods.)
91
92       No default method type; can't autoload
93           You must declare a default method type, generally by passing its
94           name to a "use Class::MakeMethods::Autoload" statement, prior to
95           autoloading any methods.
96
97       Construction of %s method %s failed to produce usable method
98           Indicates that Autoload succesfully called Class::MakeMethods->make
99           to generate the requested method, but afterwards was not able to
100           invoke the generated method. You may have selected an incompatible
101           method type, or the method may not have been installed sucesfully.
102

SEE ALSO

104       See Class::MakeMethods for general information about this distribution.
105
106
107
108perl v5.32.0                      2020-07-28          MakeMethods::Autoload(3)
Impressum