Debian Codegraph @

README

raw
1 NAME
2
3 Class::Inspector - Get information about a class and its structure
4
5 VERSION
6
7 version 1.36
8
9 SYNOPSIS
10
11 use Class::Inspector;
12
13 # Is a class installed and/or loaded
14 Class::Inspector->installed( 'Foo::Class' );
15 Class::Inspector->loaded( 'Foo::Class' );
16
17 # Filename related information
18 Class::Inspector->filename( 'Foo::Class' );
19 Class::Inspector->resolved_filename( 'Foo::Class' );
20
21 # Get subroutine related information
22 Class::Inspector->functions( 'Foo::Class' );
23 Class::Inspector->function_refs( 'Foo::Class' );
24 Class::Inspector->function_exists( 'Foo::Class', 'bar' );
25 Class::Inspector->methods( 'Foo::Class', 'full', 'public' );
26
27 # Find all loaded subclasses or something
28 Class::Inspector->subclasses( 'Foo::Class' );
29
30 DESCRIPTION
31
32 Class::Inspector allows you to get information about a loaded class.
33 Most or all of this information can be found in other ways, but they
34 aren't always very friendly, and usually involve a relatively high
35 level of Perl wizardry, or strange and unusual looking code.
36 Class::Inspector attempts to provide an easier, more friendly interface
37 to this information.
38
39 METHODS
40
41 installed
42
43 my $bool = Class::Inspector->installed($class);
44
45 The installed static method tries to determine if a class is installed
46 on the machine, or at least available to Perl. It does this by wrapping
47 around resolved_filename.
48
49 Returns true if installed/available, false if the class is not
50 installed, or undef if the class name is invalid.
51
52 loaded
53
54 my $bool = Class::Inspector->loaded($class);
55
56 The loaded static method tries to determine if a class is loaded by
57 looking for symbol table entries.
58
59 This method it uses to determine this will work even if the class does
60 not have its own file, but is contained inside a single file with
61 multiple classes in it. Even in the case of some sort of run-time
62 loading class being used, these typically leave some trace in the
63 symbol table, so an Autoload or Class::Autouse-based class should
64 correctly appear loaded.
65
66 Returns true if the class is loaded, false if not, or undef if the
67 class name is invalid.
68
69 filename
70
71 my $filename = Class::Inspector->filename($class);
72
73 For a given class, returns the base filename for the class. This will
74 NOT be a fully resolved filename, just the part of the filename BELOW
75 the @INC entry.
76
77 print Class->filename( 'Foo::Bar' );
78 > Foo/Bar.pm
79
80 This filename will be returned with the right separator for the local
81 platform, and should work on all platforms.
82
83 Returns the filename on success or undef if the class name is invalid.
84
85 resolved_filename
86
87 my $filename = Class::Inspector->resolved_filename($class);
88 my $filename = Class::Inspector->resolved_filename($class, @try_first);
89
90 For a given class, the resolved_filename static method returns the
91 fully resolved filename for a class. That is, the file that the class
92 would be loaded from.
93
94 This is not necessarily the file that the class WAS loaded from, as the
95 value returned is determined each time it runs, and the @INC include
96 path may change.
97
98 To get the actual file for a loaded class, see the loaded_filename
99 method.
100
101 Returns the filename for the class, or undef if the class name is
102 invalid.
103
104 loaded_filename
105
106 my $filename = Class::Inspector->loaded_filename($class);
107
108 For a given loaded class, the loaded_filename static method determines
109 (via the %INC hash) the name of the file that it was originally loaded
110 from.
111
112 Returns a resolved file path, or false if the class did not have it's
113 own file.
114
115 functions
116
117 my $arrayref = Class::Inspector->functions($class);
118
119 For a loaded class, the functions static method returns a list of the
120 names of all the functions in the classes immediate namespace.
121
122 Note that this is not the METHODS of the class, just the functions.
123
124 Returns a reference to an array of the function names on success, or
125 undef if the class name is invalid or the class is not loaded.
126
127 function_refs
128
129 my $arrayref = Class::Inspector->function_refs($class);
130
131 For a loaded class, the function_refs static method returns references
132 to all the functions in the classes immediate namespace.
133
134 Note that this is not the METHODS of the class, just the functions.
135
136 Returns a reference to an array of CODE refs of the functions on
137 success, or undef if the class is not loaded.
138
139 function_exists
140
141 my $bool = Class::Inspector->function_exists($class, $functon);
142
143 Given a class and function name the function_exists static method will
144 check to see if the function exists in the class.
145
146 Note that this is as a function, not as a method. To see if a method
147 exists for a class, use the can method for any class or object.
148
149 Returns true if the function exists, false if not, or undef if the
150 class or function name are invalid, or the class is not loaded.
151
152 methods
153
154 my $arrayref = Class::Inspector->methods($class, @options);
155
156 For a given class name, the methods static method will returns ALL the
157 methods available to that class. This includes all methods available
158 from every class up the class' @ISA tree.
159
160 Returns a reference to an array of the names of all the available
161 methods on success, or undef if the class name is invalid or the class
162 is not loaded.
163
164 A number of options are available to the methods method that will alter
165 the results returned. These should be listed after the class name, in
166 any order.
167
168 # Only get public methods
169 my $method = Class::Inspector->methods( 'My::Class', 'public' );
170
171 public
172
173 The public option will return only 'public' methods, as defined by
174 the Perl convention of prepending an underscore to any 'private'
175 methods. The public option will effectively remove any methods that
176 start with an underscore.
177
178 private
179
180 The private options will return only 'private' methods, as defined by
181 the Perl convention of prepending an underscore to an private
182 methods. The private option will effectively remove an method that do
183 not start with an underscore.
184
185 Note: The public and private options are mutually exclusive
186
187 full
188
189 methods normally returns just the method name. Supplying the full
190 option will cause the methods to be returned as the full names. That
191 is, instead of returning [ 'method1', 'method2', 'method3' ], you
192 would instead get [ 'Class::method1', 'AnotherClass::method2',
193 'Class::method3' ].
194
195 expanded
196
197 The expanded option will cause a lot more information about method to
198 be returned. Instead of just the method name, you will instead get an
199 array reference containing the method name as a single combined name,
200 a la full, the separate class and method, and a CODE ref to the
201 actual function ( if available ). Please note that the function
202 reference is not guaranteed to be available. Class::Inspector is
203 intended at some later time, to work with modules that have some kind
204 of common run-time loader in place ( e.g Autoloader or Class::Autouse
205 for example.
206
207 The response from methods( 'Class', 'expanded' ) would look something
208 like the following.
209
210 [
211 [ 'Class::method1', 'Class', 'method1', \&Class::method1 ],
212 [ 'Another::method2', 'Another', 'method2', \&Another::method2 ],
213 [ 'Foo::bar', 'Foo', 'bar', \&Foo::bar ],
214 ]
215
216 subclasses
217
218 my $arrayref = Class::Inspector->subclasses($class);
219
220 The subclasses static method will search then entire namespace (and
221 thus all currently loaded classes) to find all classes that are
222 subclasses of the class provided as a the parameter.
223
224 The actual test will be done by calling isa on the class as a static
225 method. (i.e. My::Class->isa($class).
226
227 Returns a reference to a list of the loaded classes that match the
228 class provided, or false is none match, or undef if the class name
229 provided is invalid.
230
231 SEE ALSO
232
233 http://ali.as/, Class::Handle, Class::Inspector::Functions
234
235 AUTHOR
236
237 Original author: Adam Kennedy <[email protected]>
238
239 Current maintainer: Graham Ollis <[email protected]>
240
241 Contributors:
242
243 Tom Wyant
244
245 Steffen Müller
246
247 Kivanc Yazan (KYZN)
248
249 COPYRIGHT AND LICENSE
250
251 This software is copyright (c) 2002-2019 by Adam Kennedy.
252
253 This is free software; you can redistribute it and/or modify it under
254 the same terms as the Perl 5 programming language system itself.
255