Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
Sub::Info(3)	      User Contributed Perl Documentation	  Sub::Info(3)

       Sub::Info - Tool	for inspecting subroutines.

       Tool to inspect subroutines.

       All exports are optional, you must specify subs to import.

       my $hr =	sub_info(\&code)
       my $hr =	sub_info(\&code, @line_numbers)
	   This	returns	a hashref with information about the sub:

		   ref	      => \&code,
		   cobj	      => $cobj,
		   name	      => "Some::Mod::code",
		   file	      => "Some/",
		   package    => "Some::Mod",

		   # Note: These have been adjusted based on guesswork.
		   start_line => 22,
		   end_line   => 42,
		   lines      => [22, 42],

		   # Not a bug,	these lines are	different!
		   all_lines  => [23, 25, ..., 39, 41],

	   $info->{ref}	=> \&code
	       This is the original sub	passed to "sub_info()".

	   $info->{cobj} => $cobj
	       This is the c-object representation of the coderef.

	   $info->{name} => "Some::Mod::code"
	       This is the name	of the coderef.	For anonymous coderefs this
	       may end with '__ANON__'.	Also note that the package 'main' is
	       special,	and 'main::' may be omitted.

	   $info->{file} => "Some/"
	       The file	in which the sub was defined.

	   $info->{package} => "Some::Mod"
	       The package in which the	sub was	defined.

	   $info->{start_line} => 22
	   $info->{end_line} =>	42
	   $info->{lines} => [22, 42]
	       These three fields are the adjusted start line, end line, and
	       array with both.	 It is important to note that these lines have
	       been adjusted and may not be accurate.

	       The lines are obtained by walking the ops. As such, the first
	       line is the line	of the first statement,	and the	last line is
	       the line	of the last statement.	This means that	in multi-line
	       subs the	lines are usually off by 1.  The lines in these	keys
	       will be adjusted	for you	if it detects a	multi-line sub.

	   $info->{all_lines} => [23, 25, ..., 39, 41]
	       This is an array	with the lines of every	statement in the sub.
	       Unlike the other	line fields, these have	not been adjusted for

       The source code repository for Sub-Info can be found at

       Chad Granum <>

       Chad Granum <>
       Kent Fredric <>

       Copyright 2016 Chad Granum <>.

       This program is free software; you can redistribute it and/or modify it
       under the same terms as Perl itself.


perl v5.32.1			  2016-12-24			  Sub::Info(3)


Want to link to this manual page? Use this URL:

home | help