1Class::MOP::Overload(3)User Contributed Perl DocumentatioCnlass::MOP::Overload(3)
2
3
4
6 Class::MOP::Overload - Overload Meta Object
7
9 version 2.2015
10
12 my $meta = Class->meta;
13 my $overload = $meta->get_overloaded_operator('+');
14
15 if ( $overload->has_method_name ) {
16 print 'Method for + is ', $overload->method_name, "\n";
17 }
18 else {
19 print 'Overloading for + is implemented by ',
20 $overload->coderef_name, " sub\n";
21 }
22
24 This class provides meta information for overloading in classes and
25 roles.
26
28 "Class::MOP::Overload" is a subclass of Class::MOP::Object.
29
31 Class::MOP::Overload->new(%options)
32 This method creates a new "Class::MOP::Overload" object. It accepts a
33 number of options:
34
35 • operator
36
37 This is a string that matches an operator known by the overload
38 module, such as "" or "+". This is required.
39
40 • method_name
41
42 The name of the method which implements the overloading. Note that
43 this does not need to actually correspond to a real method, since
44 it's okay to declare a not-yet-implemented overloading.
45
46 Either this or the "coderef" option must be passed.
47
48 • method
49
50 A Class::MOP::Method object for the method which implements the
51 overloading.
52
53 This is optional.
54
55 • coderef
56
57 A coderef which implements the overloading.
58
59 Either this or the "method_name" option must be passed.
60
61 • coderef_package
62
63 The package where the coderef was defined.
64
65 This is required if "coderef" is passed.
66
67 • coderef_name
68
69 The name of the coderef. This can be "__ANON__".
70
71 This is required if "coderef" is passed.
72
73 • associated_metaclass
74
75 A Class::MOP::Module object for the associated class or role.
76
77 This is optional.
78
79 $overload->operator
80 Returns the operator for this overload object.
81
82 $overload->method_name
83 Returns the method name that implements overloading, if it has one.
84
85 $overload->has_method_name
86 Returns true if the object has a method name.
87
88 $overload->method
89 Returns the Class::MOP::Method that implements overloading, if it has
90 one.
91
92 $overload->has_method
93 Returns true if the object has a method.
94
95 $overload->coderef
96 Returns the coderef that implements overloading, if it has one.
97
98 $overload->has_coderef
99 Returns true if the object has a coderef.
100
101 $overload->coderef_package
102 Returns the package for the coderef that implements overloading, if it
103 has one.
104
105 $overload->has_coderef
106 Returns true if the object has a coderef package.
107
108 $overload->coderef_name
109 Returns the sub name for the coderef that implements overloading, if it
110 has one.
111
112 $overload->has_coderef_name
113 Returns true if the object has a coderef name.
114
115 $overload->is_anonymous
116 Returns true if the overloading is implemented by an anonymous coderef.
117
118 $overload->associated_metaclass
119 Returns the Class::MOP::Module (class or role) that is associated with
120 the overload object.
121
122 $overload->clone
123 Clones the overloading object, setting "original_overload" in the
124 process.
125
126 $overload->original_overload
127 For cloned objects, this returns the Class::MOP::Overload object from
128 which they were cloned. This can be used to determine the source of an
129 overloading in a class that came from a role, for example.
130
132 • Stevan Little <stevan@cpan.org>
133
134 • Dave Rolsky <autarch@urth.org>
135
136 • Jesse Luehrs <doy@cpan.org>
137
138 • Shawn M Moore <sartak@cpan.org>
139
140 • יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
141
142 • Karen Etheridge <ether@cpan.org>
143
144 • Florian Ragwitz <rafl@debian.org>
145
146 • Hans Dieter Pearcey <hdp@cpan.org>
147
148 • Chris Prather <chris@prather.org>
149
150 • Matt S Trout <mstrout@cpan.org>
151
153 This software is copyright (c) 2006 by Infinity Interactive, Inc.
154
155 This is free software; you can redistribute it and/or modify it under
156 the same terms as the Perl 5 programming language system itself.
157
158
159
160perl v5.34.0 2021-07-22 Class::MOP::Overload(3)