1Rose::Object::MixIn(3)User Contributed Perl DocumentationRose::Object::MixIn(3)
2
3
4

NAME

6       Rose::Object::MixIn - A base class for mix-ins.
7

SYNOPSIS

9         package MyMixInClass;
10
11         use Rose::Object::MixIn(); # Use empty parentheses here
12         our @ISA = qw(Rose::Object::MixIn);
13
14         __PACKAGE__->export_tag(all => [ qw(my_cool_method my_other_method) ]);
15
16         sub my_cool_method  { ... }
17         sub my_other_method { ... }
18         ...
19
20         package MyClass;
21         # Import methods my_cool_method() and my_other_method()
22         use MyMixInClass qw(:all);
23         ...
24
25         package MyOtherClass;
26         # Import just my_cool_method()
27         use MyMixInClass qw(my_cool_method);
28         ...
29
30         package YetAnotherClass;
31         # Import just my_cool_method() as cool()
32         use MyMixInClass { my_cool_method => 'cool' }
33

DESCRIPTION

35       Rose::Object::MixIn is a base class for mix-ins.  A mix-in is a class
36       that exports methods into another class.  This export process is
37       controlled with an Exporter-like interface, but Rose::Object::MixIn
38       does not inherit from Exporter.
39
40       When you use a Rose::Object::MixIn-derived class, its import method is
41       called at compile time.  In other words, this:
42
43           use Rose::Object::MixIn 'a', 'b', { c => 'd' };
44
45       is the same thing as this:
46
47           BEGIN { Rose::Object::MixIn->import('a', 'b', { c => 'd' }) }
48
49       To prevent the import method from being run, put empty parentheses "()"
50       after the package name instead of a list of arguments.
51
52           use Rose::Object::MixIn();
53
54       See the synopsis for an example of when this is handy: using
55       Rose::Object::MixIn from within a subclass.  Note that the empty
56       parenthesis are important.  The following is not equivalent:
57
58           # This is not the same thing as the example above!
59           use Rose::Object::MixIn;
60
61       See the documentation for the import method below to learn what
62       arguments it accepts.
63

CLASS METHODS

65       import ARGS
66           Import the methods specified by ARGS into the package from which
67           this method was called.  If the current class can already perform
68           one of these methods, a fatal error will occur.  To override an
69           existing method, you must use the "-force" argument (see below).
70
71           Valid formats for ARGS are as follows:
72
73A method name
74
75               Literal method names will be imported as-is.
76
77A tag name
78
79               Tags names are indicated with a leading colon.  For example,
80               ":all" specifies the "all" tag.  A tag is a stand-in for a list
81               of methods.  See the export_tag method to learn how to create
82               tags.
83
84A reference to a hash
85
86               Each key/value pair in this hash contains a method name and the
87               name that it will be imported as.  Use this feature to import
88               methods under different names in order to avoid conflicts with
89               existing methods.
90
91           •   "-force"
92
93               The special literal argument "-force" will cause the specified
94               methods to be imported even if the calling class can already
95               perform one or more of those methods.
96
97           •   "-target_class CLASS"
98
99               The special literal argument "-target-class" followed by a
100               class name will cause the specified methods to be imported into
101               CLASS rather than into the calling class.
102
103           See the synopsis for several examples of the import method in
104           action.  (Remember, it's called implicitly when you use a
105           Rose::Object::MixIn-derived class with anything other than an empty
106           set of parenthesis "()" as an argument.)
107
108       clear_export_tags
109           Delete the entire list of export tags.
110
111       export_tag NAME [, ARRAYREF]
112           Get or set the list of method names associated with a tag.  The tag
113           name should not begin with a colon.  If ARRAYREF is passed, then
114           the list of methods associated with the specific tag is set.
115
116           Returns a list (in list context) or a reference to an array (in
117           scalar context) of method names.  The array reference return value
118           should be treated as read-only.  If no such tag exists, and if an
119           ARRAYREF is not passed, then a fatal error will occur.
120
121       export_tags
122           Returns a list (in list context) and a reference to an array (in
123           scalar context) containing the complete list of export tags.  The
124           array reference return value should be treated as read-only.
125

AUTHOR

127       John C. Siracusa (siracusa@gmail.com)
128

LICENSE

130       Copyright (c) 2010 by John C. Siracusa.  All rights reserved.  This
131       program is free software; you can redistribute it and/or modify it
132       under the same terms as Perl itself.
133
134
135
136perl v5.38.0                      2023-07-21            Rose::Object::MixIn(3)
Impressum