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' );

  # Find all loaded subclasses or something
  Class::Inspector->subclasses( 'Foo::Class' );

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 aren't always very friendly, and usually involve a relatively high level of Perl wizardry, or strange and unusual looking code. Class::Inspector attempts to provide an easier, more friendly interface to this information.

METHODS

The \*(C`installed\*(C' static method tries to determine if a class is installed on the machine, or at least available to Perl. It does this by wrapping around \*(C`resolved_filename\*(C'.

Returns true if installed/available, false if the class is not installed, or \*(C`undef\*(C' if the class name is invalid. The \*(C`loaded\*(C' static method tries to determine if a class is loaded by looking for symbol table entries.

This method it uses to determine this will work even if the class does not have its own file, but is contained inside a single file with multiple classes in it. 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 Autoload or Class::Autouse-based class should correctly appear loaded.

Returns true if the class is loaded, false if not, or \*(C`undef\*(C' if the class name is invalid. For a given class, returns the base filename for the class. This will \s-1NOT\s0 be a fully resolved filename, just the part of the filename \s-1BELOW\s0 the @INC entry.

print Class->filename( 'Foo::Bar' ); > Foo/Bar.pm

This filename will be returned with the right separator for the local platform, and should work on all platforms.

Returns the filename on success or \*(C`undef\*(C' if the class name is invalid. For a given class, the \*(C`resolved_filename\*(C' static method 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 \s-1WAS\s0 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 \*(C`loaded_filename\*(C' method.

Returns the filename for the class, or \*(C`undef\*(C' if the class name is invalid. For a given loaded class, the \*(C`loaded_filename\*(C' static method determines (via the %INC hash) the name of the file that it was originally loaded from.

Returns a resolved file path, or false if the class did not have it's own file. For a loaded class, the \*(C`functions\*(C' static method returns a list of the names of all the functions in the classes immediate namespace.

Note that this is not the \s-1METHODS\s0 of the class, just the functions.

Returns a reference to an array of the function names on success, or \*(C`undef\*(C' if the class name is invalid or the class is not loaded. For a loaded class, the \*(C`function_refs\*(C' static method returns references to all the functions in the classes immediate namespace.

Note that this is not the \s-1METHODS\s0 of the class, just the functions.

Returns a reference to an array of \*(C`CODE\*(C' refs of the functions on success, or \*(C`undef\*(C' if the class is not loaded. Given a class and function name the \*(C`function_exists\*(C' static 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 \*(C`can\*(C' method for any class or object.

Returns true if the function exists, false if not, or \*(C`undef\*(C' if the class or function name are invalid, or the class is not loaded. For a given class name, the \*(C`methods\*(C' static method will returns \s-1ALL\s0 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, or \*(C`undef\*(C' if the class name is invalid or the class is not loaded.

A number of options are available to the \*(C`methods\*(C' method that will alter the results returned. These should be listed after the class name, in any order.

# Only get public methods my $method = Class::Inspector->methods( 'My::Class', 'public' );

public

The \*(C`public\*(C' option will return only 'public' methods, as defined by the Perl convention of prepending an underscore to any 'private' methods. The \*(C`public\*(C' option will effectively remove any methods that start with an underscore.

private

The \*(C`private\*(C' options will return only 'private' methods, as defined by the Perl convention of prepending an underscore to an private methods. The \*(C`private\*(C' option will effectively remove an method that do not start with an underscore. Note: The \*(C`public\*(C' and \*(C`private\*(C' options are mutually exclusive

full

\*(C`methods\*(C' normally returns just the method name. Supplying the \*(C`full\*(C' option will cause the methods to be returned as the full names. That is, instead of returning \*(C`[ 'method1', 'method2', 'method3' ]\*(C', you would instead get \*(C`[ 'Class::method1', 'AnotherClass::method2', 'Class::method3' ]\*(C'.

expanded

The \*(C`expanded\*(C' 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 \*(C`full\*(C', the separate class and method, and a \s-1CODE\s0 ref to the actual function ( if available ). Please note that the function reference is not guarenteed to be available. \*(C`Class::Inspector\*(C' is intended at some later time, work with modules that have some some of common run-time loader in place ( e.g \*(C`Autoloader\*(C' or \*(C`Class::Autouse\*(C' for example. The response from \*(C`methods( 'Class', 'expanded' )\*(C' would look something like the following. [ [ 'Class::method1', 'Class', 'method1', \&Class::method1 ], [ 'Another::method2', 'Another', 'method2', \&Another::method2 ], [ 'Foo::bar', 'Foo', 'bar', \&Foo::bar ], ] The \*(C`subclasses\*(C' static method will search then entire namespace (and thus all currently loaded classes) to find all classes that are subclasses of the class provided as a the parameter.

The actual test will be done by calling \*(C`isa\*(C' on the class as a static method. (i.e. \*(C`My::Class->isa($class)\*(C'.

Returns a reference to a list of the loaded classes that match the class provided, or false is none match, or \*(C`undef\*(C' if the class name provided is invalid.

SUPPORT

Bugs should be reported via the \s-1CPAN\s0 bug tracker

http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Inspector <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Inspector>

For other issues, or commercial enhancement or support, contact the author.

AUTHOR

Adam Kennedy <[email protected]>

RELATED TO Class::Inspector…

<http://ali.as/>, Class::Handle

COPYRIGHT

Copyright 2002 - 2012 Adam Kennedy.

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 \s-1LICENSE\s0 file included with this module.