Class::Inspector - Get information about a class and its structure
| Use Case | Command | Description |
|---|---|---|
| Check if class is installed | Class::Inspector->installed('Foo::Class') | Returns true if the class is available to Perl. |
| Check if class is loaded | Class::Inspector->loaded('Foo::Class') | Returns true if the class is in the symbol table. |
| Get base filename | Class::Inspector->filename('Foo::Class') | Returns path like Foo/Bar.pm (platformβsensitive). |
| Get fully resolved filename | Class::Inspector->resolved_filename('Foo::Class') | Finds the file that would be used to load the class. |
| Get actual loaded filename | Class::Inspector->loaded_filename('Foo::Class') | Returns the file from %INC that the class was originally loaded from. |
| List functions in namespace | Class::Inspector->functions('Foo::Class') | Returns arrayref of function names (not methods). |
| Get code references to functions | Class::Inspector->function_refs('Foo::Class') | Returns arrayref of CODE refs. |
| Check if a function exists | Class::Inspector->function_exists('Foo::Class', 'bar') | Checks function existence (not method). |
| List all methods for a class | Class::Inspector->methods('Foo::Class') | Returns arrayref of all method names (inherited). |
| Find loaded subclasses | Class::Inspector->subclasses('Foo::Class') | Returns arrayref of classes that isa the given class. |
version 1.36
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' );
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.
my $bool = Class::Inspector->installed($class);
The installed 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 resolved_filename.
Returns true if installed/available, false if the class is not installed, or undef if the class name is invalid.
my $bool = Class::Inspector->loaded($class);
The loaded static method 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 its own file (e.g., multiple classes in one file) or is loaded via runβtime loaders like Autoload or Class::Autouse.
Returns true if the class is loaded, false if not, or undef if the class name is invalid.
my $filename = Class::Inspector->filename($class);
For a given class, returns the base filename (the part below @INC).
print Class->filename( 'Foo::Bar' );
> Foo/Bar.pm
This filename is returned with the correct separator for the local platform.
Returns the filename on success or undef if the class name is invalid.
my $filename = Class::Inspector->resolved_filename($class);
my $filename = Class::Inspector->resolved_filename($class, @try_first);
Returns the fully resolved filename for a class (the file that would be loaded from). This is not necessarily the file that was actually loaded; see loaded_filename for that.
Returns the filename or undef if the class name is invalid.
my $filename = Class::Inspector->loaded_filename($class);
For a given loaded class, determines via %INC the name of the file it was originally loaded from.
Returns a resolved file path, or false if the class did not have its own file.
my $arrayref = Class::Inspector->functions($class);
Returns a list of the names of all functions in the classβs immediate namespace (not methods).
Returns an arrayref of function names on success, or undef if the class is invalid or not loaded.
my $arrayref = Class::Inspector->function_refs($class);
Returns references to all functions in the classβs immediate namespace (not methods).
Returns an arrayref of CODE refs on success, or undef if the class is not loaded.
my $bool = Class::Inspector->function_exists($class, $functon);
Checks if a function exists in the given class (as a function, not a method). For method existence, use can.
Returns true if the function exists, false if not, or undef if the class is invalid or not loaded.
my $arrayref = Class::Inspector->methods($class, @options);
Returns ALL methods available to the class (including inherited methods up the @ISA tree).
Returns an arrayref of method names on success, or undef if the class is invalid or not loaded.
Options can be passed after the class name:
public).Class::method1).[
[ 'Class::method1', 'Class', 'method1', \&Class::method1 ],
[ 'Another::method2', 'Another', 'method2', \&Another::method2 ],
[ 'Foo::bar', 'Foo', 'bar', \&Foo::bar ],
]
my $arrayref = Class::Inspector->subclasses($class);
Searches the entire namespace to find all loaded classes that are subclasses of the given class (via isa).
Returns an arrayref of matching classes, or false if none, or undef if the class name is invalid.
Original author: Adam Kennedy <adamk AT cpan.org>
Current maintainer: Graham Ollis <plicease AT cpan.org>
Contributors: Tom Wyant, Steffen MΓΌller, Kivanc Yazan (KYZN)
This software is copyright (c) 2002-2019 by Adam Kennedy.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
```Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-16 09:27 @2600:1f28:365:80b0:7cb9:fb:26c1:e368
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)