NAME Class::Inspector - Provides information about Classes SYNOPSIS use Class::Inspector; # Is a class installed and/or loaded Class::Inspector->installed( 'Foo::Class' ); Class::Inspector->loaded( 'Foo::Class' ); # Filename related information Class::Inspector->filename( 'Foo::Class' ); Class::Inspector->resolved_filename( 'Foo::Class' ); # Get subroutine related information Class::Inspector->functions( 'Foo::Class' ); Class::Inspector->function_refs( 'Foo::Class' ); Class::Inspector->function_exists( 'Foo::Class', 'bar' ); Class::Inspector->methods( 'Foo::Class', 'full', 'public' ); DESCRIPTION Class::Inspector allows you to get information about a loaded class. Most or all of this information can be found in other ways, but they arn't always very friendly, and usually involve a relatively high level of Perl wizardry, or strange or unusual looking code. Class::Inspector attempts to provide an easier, more friendly interface to this information. METHODS installed( $class ) Tries to determine is a class is installed on the machine, or at least available to Perl. It does this by essentially wrapping around "resolved_filename". Returns true if installed/available, returns 0 if the class is not installed. Returns undef if the class name is invalid. loaded( $class ) Tries to determine if a class is loaded by looking for symbol table entries. This method will work even if the class does not have it's own file, but is contained inside a single module with multiple package/classes. Even in the case of some sort of run-time loading class being used, these typically leave some trace in the symbol table, so an "Class::Autouse" or "Autoload" based class should correctly appear loaded. filename( $class ) For a given class, returns the base filename for the class. This will NOT be a fully resolved filename, just the part of the filename BELOW the @INC entry. For example: Class->filename( 'Foo::Bar' ) returns 'Foo/Bar.pm' This filename will be returned for the current platform. It should work on all platforms. Returns the filename on success. Returns undef on error, which could only really be caused by an invalid class name. resolved_filename( $class, @try_first ) For a given class, returns the fully resolved filename for a class. That is, the file that the class would be loaded from. This is not nescesarily the file that the class WAS loaded from, as the value returned is determined each time it runs, and the @INC include path may change. To get the actual file for a loaded class, see the "loaded_filename" method. Returns the filename for the class on success. Returns undef on error. loaded_filename( $class ) For a given, loaded, class, returns the name of the file that it was originally loaded from. Returns false if the class is not loaded, or did not have it's own file. functions( $class ) Returns a list of the names of all the functions in the classes immediate namespace. Note that this is not the METHODS of the class, just the functions. Returns a reference to an array of the function names on success. Returns undef on error or if the class is not loaded. function_refs( $class ) Returns a list of references to all the functions in the classes immediate namespace. Returns a reference to an array of CODE refs of the functions on success. Returns undef on error or if the class is not loaded. function_exists( $class, $function ) Given a class and function the "function_exists" method will check to see if the function exists in the class. Note that this is as a function, not as a method. To see if a method exists for a class, use the "can" method in UNIVERSAL, and hence to every other class. Returns 1 if the function exists. Returns 0 if the function does not exist. Returns undef on error, or if the class is not loaded. methods( $class, @options ) For a given class name, the "methods" method will returns ALL the methods available to that class. This includes all methods available from every class up the class' @ISA tree. Returns a reference to an array of the names of all the available methods on success. Returns undef if the class is not loaded. A number of options are available to the "methods" method. These should be listed after the class name, in any order. public The "public" option will return only 'public' methods, as defined by the Perl convention of prepending an underscore to any 'private' methods. The "public" option will effectively remove any methods that start with an underscore. private The "private" options will return only 'private' methods, as defined by the Perl convention of prepending an underscore to an private methods. The "private" option will effectively remove an method that do not start with an underscore. Note: The "public" and "private" options are mutually exclusive full "methods" normally returns just the method name. Supplying the "full" option will cause the methods to be returned as the full names. That is, instead of returning "[ 'method1', 'method2', 'method3' ]", you would instead get "[ 'Class::method1', 'AnotherClass::method2', 'Class::method3' ]". expanded The "expanded" option will cause a lot more information about method to be returned. Instead of just the method name, you will instead get an array reference containing the method name as a single combined name, ala "full", the seperate class and method, and a CODE ref to the actual function ( if available ). Please note that the function reference is not guarenteed to be available. c is intended at some later time, work with modules that have some some of common run-time loader in place ( e.g "Autoloader" or "Class::Autouse" for example. The response from "methods( 'Class', 'expanded' )" would look something like the following. [ [ 'Class::method1', 'Class', 'method1', \&Class::method1 ], [ 'Another::method2', 'Another', 'method2', \&Another::method2 ], [ 'Foo::bar', 'Foo', 'bar', \&Foo::bar ], ] BUGS No known bugs, but I'm taking suggestions for additional functionality. SUPPORT Contact the author AUTHOR Adam Kennedy cpan@ali.as http://ali.as/ SEE ALSO Class::Handle, which wraps this one COPYRIGHT Copyright (c) 2002 Adam Kennedy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module.