perldoc > Class::Inspector

πŸ“¦ NAME

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

πŸš€ Quick Reference

πŸ“‹ Use CaseπŸ’» CommandπŸ“ Description
Check if class is installedClass::Inspector->installed('Foo::Class')Returns true if class is available on the system
Check if class is loadedClass::Inspector->loaded('Foo::Class')Returns true if class is loaded in memory
Get base filenameClass::Inspector->filename('Foo::Class')Returns platform-appropriate base filename (e.g., Foo/Bar.pm)
Get resolved filenameClass::Inspector->resolved_filename('Foo::Class')Returns fully resolved file path from @INC
Get functions listClass::Inspector->functions('Foo::Class')Returns arrayref of function names in the class namespace
Get methodsClass::Inspector->methods('Foo::Class', 'public')Returns arrayref of methods, with options: public, private, full, expanded
Find subclassesClass::Inspector->subclasses('Foo::Class')Returns arrayref of all loaded subclasses

🏷️ VERSION

version 1.36

πŸ“‹ 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

βœ… installed

     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.

πŸ“¦ loaded

     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 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 undef if the class name is invalid.

πŸ“ filename

     my $filename = Class::Inspector->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.

      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 undef if the class name is invalid.

πŸ” resolved_filename

     my $filename = Class::Inspector->resolved_filename($class);
     my $filename = Class::Inspector->resolved_filename($class, @try_first);

For a given class, the resolved_filename static method returns the fully resolved filename for a class. That is, the file that the class would be loaded from.

This is not necessarily 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, or undef if the class name is invalid.

πŸ“„ loaded_filename

     my $filename = Class::Inspector->loaded_filename($class);

For a given loaded class, the loaded_filename 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 its own file.

πŸ“‹ functions

     my $arrayref = Class::Inspector->functions($class);

For a loaded class, the functions static method 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, or undef if the class name is invalid or the class is not loaded.

πŸ”— function_refs

     my $arrayref = Class::Inspector->function_refs($class);

For a loaded class, the function_refs static method returns references to 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 CODE refs of the functions on success, or undef if the class is not loaded.

❓ function_exists

     my $bool = Class::Inspector->function_exists($class, $function);

Given a class and function name the function_exists 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 can method for any class or object.

Returns true if the function exists, false if not, or undef if the class or function name are invalid, or the class is not loaded.

πŸ› οΈ methods

     my $arrayref = Class::Inspector->methods($class, @options);

For a given class name, the methods static method will return 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, or undef if the class name is invalid or the class is not loaded.

A number of options are available to the methods 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' );

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         ],
      ]

🧬 subclasses

     my $arrayref = Class::Inspector->subclasses($class);

The subclasses static method will search the entire namespace (and thus all currently loaded classes) to find all classes that are subclasses of the class provided as the parameter.

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

Returns a reference to a list of the loaded classes that match the class provided, or false if none match, or undef if the class name provided is invalid.

πŸ”— SEE ALSO

http://ali.as/, Class::Handle, Class::Inspector::Functions

πŸ‘€ AUTHOR

Original author: Adam Kennedy <adamk AT cpan.org>

Current maintainer: Graham Ollis <plicease AT cpan.org>

Contributors:

πŸ“œ COPYRIGHT AND LICENSE

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.

Class::Inspector
πŸ“¦ NAME πŸš€ Quick Reference 🏷️ VERSION πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION πŸ”§ METHODS
βœ… installed πŸ“¦ loaded πŸ“ filename πŸ” resolved_filename πŸ“„ loaded_filename πŸ“‹ functions πŸ”— function_refs ❓ function_exists πŸ› οΈ methods 🧬 subclasses
πŸ”— SEE ALSO πŸ‘€ AUTHOR πŸ“œ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-08 16:39 @216.73.216.150
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^