1Class::Inspector(3)   User Contributed Perl Documentation  Class::Inspector(3)
2
3
4

NAME

6       Class::Inspector - Get information about a class and its structure
7

VERSION

9       version 1.36
10

SYNOPSIS

12         use Class::Inspector;
13
14         # Is a class installed and/or loaded
15         Class::Inspector->installed( 'Foo::Class' );
16         Class::Inspector->loaded( 'Foo::Class' );
17
18         # Filename related information
19         Class::Inspector->filename( 'Foo::Class' );
20         Class::Inspector->resolved_filename( 'Foo::Class' );
21
22         # Get subroutine related information
23         Class::Inspector->functions( 'Foo::Class' );
24         Class::Inspector->function_refs( 'Foo::Class' );
25         Class::Inspector->function_exists( 'Foo::Class', 'bar' );
26         Class::Inspector->methods( 'Foo::Class', 'full', 'public' );
27
28         # Find all loaded subclasses or something
29         Class::Inspector->subclasses( 'Foo::Class' );
30

DESCRIPTION

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

METHODS

40   installed
41        my $bool = Class::Inspector->installed($class);
42
43       The "installed" static method tries to determine if a class is
44       installed on the machine, or at least available to Perl. It does this
45       by wrapping around "resolved_filename".
46
47       Returns true if installed/available, false if the class is not
48       installed, or "undef" if the class name is invalid.
49
50   loaded
51        my $bool = Class::Inspector->loaded($class);
52
53       The "loaded" static method tries to determine if a class is loaded by
54       looking for symbol table entries.
55
56       This method it uses to determine this will work even if the class does
57       not have its own file, but is contained inside a single file with
58       multiple classes in it. Even in the case of some sort of run-time
59       loading class being used, these typically leave some trace in the
60       symbol table, so an Autoload or Class::Autouse-based class should
61       correctly appear loaded.
62
63       Returns true if the class is loaded, false if not, or "undef" if the
64       class name is invalid.
65
66   filename
67        my $filename = Class::Inspector->filename($class);
68
69       For a given class, returns the base filename for the class. This will
70       NOT be a fully resolved filename, just the part of the filename BELOW
71       the @INC entry.
72
73         print Class->filename( 'Foo::Bar' );
74         > Foo/Bar.pm
75
76       This filename will be returned with the right separator for the local
77       platform, and should work on all platforms.
78
79       Returns the filename on success or "undef" if the class name is
80       invalid.
81
82   resolved_filename
83        my $filename = Class::Inspector->resolved_filename($class);
84        my $filename = Class::Inspector->resolved_filename($class, @try_first);
85
86       For a given class, the "resolved_filename" static method returns the
87       fully resolved filename for a class. That is, the file that the class
88       would be loaded from.
89
90       This is not necessarily the file that the class WAS loaded from, as the
91       value returned is determined each time it runs, and the @INC include
92       path may change.
93
94       To get the actual file for a loaded class, see the "loaded_filename"
95       method.
96
97       Returns the filename for the class, or "undef" if the class name is
98       invalid.
99
100   loaded_filename
101        my $filename = Class::Inspector->loaded_filename($class);
102
103       For a given loaded class, the "loaded_filename" static method
104       determines (via the %INC hash) the name of the file that it was
105       originally loaded from.
106
107       Returns a resolved file path, or false if the class did not have it's
108       own file.
109
110   functions
111        my $arrayref = Class::Inspector->functions($class);
112
113       For a loaded class, the "functions" static method returns a list of the
114       names of all the functions in the classes immediate namespace.
115
116       Note that this is not the METHODS of the class, just the functions.
117
118       Returns a reference to an array of the function names on success, or
119       "undef" if the class name is invalid or the class is not loaded.
120
121   function_refs
122        my $arrayref = Class::Inspector->function_refs($class);
123
124       For a loaded class, the "function_refs" static method returns
125       references to all the functions in the classes immediate namespace.
126
127       Note that this is not the METHODS of the class, just the functions.
128
129       Returns a reference to an array of "CODE" refs of the functions on
130       success, or "undef" if the class is not loaded.
131
132   function_exists
133        my $bool = Class::Inspector->function_exists($class, $functon);
134
135       Given a class and function name the "function_exists" static method
136       will check to see if the function exists in the class.
137
138       Note that this is as a function, not as a method. To see if a method
139       exists for a class, use the "can" method for any class or object.
140
141       Returns true if the function exists, false if not, or "undef" if the
142       class or function name are invalid, or the class is not loaded.
143
144   methods
145        my $arrayref = Class::Inspector->methods($class, @options);
146
147       For a given class name, the "methods" static method will returns ALL
148       the methods available to that class. This includes all methods
149       available from every class up the class' @ISA tree.
150
151       Returns a reference to an array of the names of all the available
152       methods on success, or "undef" if the class name is invalid or the
153       class is not loaded.
154
155       A number of options are available to the "methods" method that will
156       alter the results returned. These should be listed after the class
157       name, in any order.
158
159         # Only get public methods
160         my $method = Class::Inspector->methods( 'My::Class', 'public' );
161
162       public
163           The "public" option will return only 'public' methods, as defined
164           by the Perl convention of prepending an underscore to any 'private'
165           methods. The "public" option will effectively remove any methods
166           that start with an underscore.
167
168       private
169           The "private" options will return only 'private' methods, as
170           defined by the Perl convention of prepending an underscore to an
171           private methods. The "private" option will effectively remove an
172           method that do not start with an underscore.
173
174           Note: The "public" and "private" options are mutually exclusive
175
176       full
177           "methods" normally returns just the method name. Supplying the
178           "full" option will cause the methods to be returned as the full
179           names. That is, instead of returning "[ 'method1', 'method2',
180           'method3' ]", you would instead get "[ 'Class::method1',
181           'AnotherClass::method2', 'Class::method3' ]".
182
183       expanded
184           The "expanded" option will cause a lot more information about
185           method to be returned. Instead of just the method name, you will
186           instead get an array reference containing the method name as a
187           single combined name, a la "full", the separate class and method,
188           and a CODE ref to the actual function ( if available ). Please note
189           that the function reference is not guaranteed to be available.
190           "Class::Inspector" is intended at some later time, to work with
191           modules that have some kind of common run-time loader in place (
192           e.g "Autoloader" or "Class::Autouse" for example.
193
194           The response from "methods( 'Class', 'expanded' )" would look
195           something like the following.
196
197             [
198               [ 'Class::method1',   'Class',   'method1', \&Class::method1   ],
199               [ 'Another::method2', 'Another', 'method2', \&Another::method2 ],
200               [ 'Foo::bar',         'Foo',     'bar',     \&Foo::bar         ],
201             ]
202
203   subclasses
204        my $arrayref = Class::Inspector->subclasses($class);
205
206       The "subclasses" static method will search then entire namespace (and
207       thus all currently loaded classes) to find all classes that are
208       subclasses of the class provided as a the parameter.
209
210       The actual test will be done by calling "isa" on the class as a static
211       method. (i.e. "My::Class->isa($class)".
212
213       Returns a reference to a list of the loaded classes that match the
214       class provided, or false is none match, or "undef" if the class name
215       provided is invalid.
216

SEE ALSO

218       <http://ali.as/>, Class::Handle, Class::Inspector::Functions
219

AUTHOR

221       Original author: Adam Kennedy <adamk@cpan.org>
222
223       Current maintainer: Graham Ollis <plicease@cpan.org>
224
225       Contributors:
226
227       Tom Wyant
228
229       Steffen Müller
230
231       Kivanc Yazan (KYZN)
232
234       This software is copyright (c) 2002-2019 by Adam Kennedy.
235
236       This is free software; you can redistribute it and/or modify it under
237       the same terms as the Perl 5 programming language system itself.
238
239
240
241perl v5.38.0                      2023-07-20               Class::Inspector(3)
Impressum