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

SYNOPSIS

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

DESCRIPTION

29       Class::Inspector allows you to get information about a loaded class.
30       Most or all of this information can be found in other ways, but they
31       aren't always very friendly, and usually involve a relatively high
32       level of Perl wizardry, or strange and unusual looking code.
33       Class::Inspector attempts to provide an easier, more friendly interface
34       to this information.
35

METHODS

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

SUPPORT

194       Bugs should be reported via the CPAN bug tracker
195
196       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Inspector>
197
198       For other issues, or commercial enhancement or support, contact the
199       author.
200

AUTHOR

202       Adam Kennedy <adamk@cpan.org>
203

SEE ALSO

205       <http://ali.as/>, Class::Handle
206
208       Copyright 2002 - 2012 Adam Kennedy.
209
210       This program is free software; you can redistribute it and/or modify it
211       under the same terms as Perl itself.
212
213       The full text of the license can be found in the LICENSE file included
214       with this module.
215
216
217
218perl v5.16.3                      2012-10-19               Class::Inspector(3)
Impressum