{"id":6980,"date":"2022-12-20T19:34:34","date_gmt":"2022-12-20T22:34:34","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/classinspector-man3\/"},"modified":"2022-12-20T19:34:34","modified_gmt":"2022-12-20T22:34:34","slug":"classinspector-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/classinspector-man3\/","title":{"rendered":"Class::Inspector (man3)"},"content":{"rendered":"<h1 align=\"center\">Class::Inspector<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#VERSION\">VERSION<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#METHODS\">METHODS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a><br \/> <a href=\"#COPYRIGHT AND LICENSE\">COPYRIGHT AND LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Class::Inspector \u2212 Get information about a class and its structure<\/p>\n<h2>VERSION <a name=\"VERSION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">version 1.36<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use Class::Inspector; <br \/> # Is a class installed and\/or loaded <br \/> Class::Inspector\u2212>installed( &#8216;Foo::Class&#8217; ); <br \/> Class::Inspector\u2212>loaded( &#8216;Foo::Class&#8217; ); <br \/> # Filename related information <br \/> Class::Inspector\u2212>filename( &#8216;Foo::Class&#8217; ); <br \/> Class::Inspector\u2212>resolved_filename( &#8216;Foo::Class&#8217; ); <br \/> # Get subroutine related information <br \/> Class::Inspector\u2212>functions( &#8216;Foo::Class&#8217; ); <br \/> Class::Inspector\u2212>function_refs( &#8216;Foo::Class&#8217; ); <br \/> Class::Inspector\u2212>function_exists( &#8216;Foo::Class&#8217;, &#8216;bar&#8217; ); <br \/> Class::Inspector\u2212>methods( &#8216;Foo::Class&#8217;, &#8216;full&#8217;, &#8216;public&#8217; ); <br \/> # Find all loaded subclasses or something <br \/> Class::Inspector\u2212>subclasses( &#8216;Foo::Class&#8217; );<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">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\u2019t 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.<\/p>\n<h2>METHODS <a name=\"METHODS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>installed<\/b> <br \/> my $bool = Class::Inspector\u2212>installed($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The &#8220;installed&#8221; 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 &#8220;resolved_filename&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns true if installed\/available, false if the class is not installed, or &#8220;undef&#8221; if the class name is invalid.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>loaded<\/b> <br \/> my $bool = Class::Inspector\u2212>loaded($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The &#8220;loaded&#8221; static method tries to determine if a class is loaded by looking for symbol table entries.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">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\u2212based class should correctly appear loaded.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns true if the class is loaded, false if not, or &#8220;undef&#8221; if the class name is invalid.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>filename<\/b> <br \/> my $filename = Class::Inspector\u2212>filename($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a given class, returns the base filename for the class. This will <small>NOT<\/small> be a fully resolved filename, just the part of the filename <small>BELOW<\/small> the @INC entry.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">print Class\u2212>filename( &#8216;Foo::Bar&#8217; ); <br \/> > Foo\/Bar.pm<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This filename will be returned with the right separator for the local platform, and should work on all platforms.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns the filename on success or &#8220;undef&#8221; if the class name is invalid.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>resolved_filename<\/b> <br \/> my $filename = Class::Inspector\u2212>resolved_filename($class); <br \/> my $filename = Class::Inspector\u2212>resolved_filename($class, @try_first);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a given class, the &#8220;resolved_filename&#8221; static method returns the fully resolved filename for a class. That is, the file that the class would be loaded from.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This is not necessarily the file that the class <small>WAS<\/small> loaded from, as the value returned is determined each time it runs, and the @INC include path may change.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">To get the actual file for a loaded class, see the &#8220;loaded_filename&#8221; method.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns the filename for the class, or &#8220;undef&#8221; if the class name is invalid.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>loaded_filename<\/b> <br \/> my $filename = Class::Inspector\u2212>loaded_filename($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a given loaded class, the &#8220;loaded_filename&#8221; static method determines (via the %INC hash) the name of the file that it was originally loaded from.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns a resolved file path, or false if the class did not have it\u2019s own file.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>functions<\/b> <br \/> my $arrayref = Class::Inspector\u2212>functions($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a loaded class, the &#8220;functions&#8221; static method returns a list of the names of all the functions in the classes immediate namespace.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that this is not the <small>METHODS<\/small> of the class, just the functions.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns a reference to an array of the function names on success, or &#8220;undef&#8221; if the class name is invalid or the class is not loaded.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>function_refs<\/b> <br \/> my $arrayref = Class::Inspector\u2212>function_refs($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a loaded class, the &#8220;function_refs&#8221; static method returns references to all the functions in the classes immediate namespace.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that this is not the <small>METHODS<\/small> of the class, just the functions.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns a reference to an array of &#8220;CODE&#8221; refs of the functions on success, or &#8220;undef&#8221; if the class is not loaded.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>function_exists<\/b> <br \/> my $bool = Class::Inspector\u2212>function_exists($class, $functon);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Given a class and function name the &#8220;function_exists&#8221; static method will check to see if the function exists in the class.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Note that this is as a function, not as a method. To see if a method exists for a class, use the &#8220;can&#8221; method for any class or object.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns true if the function exists, false if not, or &#8220;undef&#8221; if the class or function name are invalid, or the class is not loaded.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>methods<\/b> <br \/> my $arrayref = Class::Inspector\u2212>methods($class, @options);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For a given class name, the &#8220;methods&#8221; static method will returns <small>ALL<\/small> the methods available to that class. This includes all methods available from every class up the class\u2019 @ISA tree.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns a reference to an array of the names of all the available methods on success, or &#8220;undef&#8221; if the class name is invalid or the class is not loaded.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">A number of options are available to the &#8220;methods&#8221; method that will alter the results returned. These should be listed after the class name, in any order.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"># Only get public methods <br \/> my $method = Class::Inspector\u2212>methods( &#8216;My::Class&#8217;, &#8216;public&#8217; ); <br \/> public<\/p>\n<p style=\"margin-left:17%;\">The &#8220;public&#8221; option will return only \u2019public\u2019 methods, as defined by the Perl convention of prepending an underscore to any \u2019private\u2019 methods. The &#8220;public&#8221; option will effectively remove any methods that start with an underscore.<\/p>\n<p style=\"margin-left:11%;\">private<\/p>\n<p style=\"margin-left:17%;\">The &#8220;private&#8221; options will return only \u2019private\u2019 methods, as defined by the Perl convention of prepending an underscore to an private methods. The &#8220;private&#8221; option will effectively remove an method that do not start with an underscore.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>Note: The &#8220;public&#8221; and &#8220;private&#8221; options are mutually exclusive<\/b><\/p>\n<p style=\"margin-left:11%;\">full<\/p>\n<p style=\"margin-left:17%;\">&#8220;methods&#8221; normally returns just the method name. Supplying the &#8220;full&#8221; option will cause the methods to be returned as the full names. That is, instead of returning &#8220;[ &#8216;method1&#8217;, &#8216;method2&#8217;, &#8216;method3&#8217; ]&#8221;, you would instead get &#8220;[ &#8216;Class::method1&#8217;, &#8216;AnotherClass::method2&#8217;, &#8216;Class::method3&#8217; ]&#8221;.<\/p>\n<p style=\"margin-left:11%;\">expanded<\/p>\n<p style=\"margin-left:17%;\">The &#8220;expanded&#8221; 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, a la &#8220;full&#8221;, the separate class and method, and a <small>CODE<\/small> ref to the actual function ( if available ). Please note that the function reference is not guaranteed to be available. &#8220;Class::Inspector&#8221; is intended at some later time, to work with modules that have some kind of common run-time loader in place ( e.g &#8220;Autoloader&#8221; or &#8220;Class::Autouse&#8221; for example.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">The response from &#8220;methods( &#8216;Class&#8217;, &#8216;expanded&#8217; )&#8221; would look something like the following.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">[ <br \/> [ &#8216;Class::method1&#8217;, &#8216;Class&#8217;, &#8216;method1&#8217;, &#038;Class::method1 ], <br \/> [ &#8216;Another::method2&#8217;, &#8216;Another&#8217;, &#8216;method2&#8217;, &#038;Another::method2 ], <br \/> [ &#8216;Foo::bar&#8217;, &#8216;Foo&#8217;, &#8216;bar&#8217;, &#038;Foo::bar ], <br \/> ]<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>subclasses<\/b> <br \/> my $arrayref = Class::Inspector\u2212>subclasses($class);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The &#8220;subclasses&#8221; static method will search then entire namespace (and thus <b>all<\/b> currently loaded classes) to find all classes that are subclasses of the class provided as a the parameter.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The actual test will be done by calling &#8220;isa&#8221; on the class as a static method. (i.e. &#8220;My::Class\u2212>isa($class)&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Returns a reference to a list of the loaded classes that match the class provided, or false is none match, or &#8220;undef&#8221; if the class name provided is invalid.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><http:\/\/ali.as\/>, Class::Handle, Class::Inspector::Functions<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Original author: Adam Kennedy <adamk@cpan.org><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Current maintainer: Graham Ollis <plicease@cpan.org><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Contributors:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Tom Wyant<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Steffen M\u00c3\u00bcller<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Kivanc Yazan ( <small>KYZN<\/small> )<\/p>\n<h2>COPYRIGHT AND LICENSE <a name=\"COPYRIGHT AND LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This software is copyright (c) 2002\u22122019 by Adam Kennedy.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This is free software; you can redistribute it and\/or modify it under the same terms as the Perl 5 programming language system itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Class::Inspector \u2212 Get information about a class and its structure <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3330,3007],"class_list":["post-6980","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-classinspector","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6980"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6980\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}