Next Tricks of the Wizards 187

Examine Source Code

        package Devel::Dumpcode;
        sub DB::DB { }    # Do nothing special
        sub main::source_of_function {
          my $package = caller;
          $function = $package . '::' . shift();
          my ($file, $start, $end) =
            $DB::sub{$function} =~ /(.*):(\d+)-(\d+)/;
          @{"::_<$file"}[$start..$end];
        }
        print source_of_function('foo')

to print out the source of function foo



Next Copyright © 2003 M. J. Dominus