Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Retrieving start and end line numbers of a subroutine in a Perl file

by stevieb (Canon)
on Jun 26, 2015 at 13:04 UTC ( [id://1132144]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Retrieving start and end line numbers of a subroutine in a Perl file
in thread Retrieving start and end line numbers of a subroutine in a Perl file

The original reason I wrote this module is because I was creating a very large multi-module application, and wanted a quick way to search through all functions/methods to see what needed tending to. I'd always be consistent like #bug 135 or #FIXME: blah. This method of use of the module will print out all sub names that contain a particular search term.

Here's an example of that and some sample output. I ran it something like this:

$ ./des.pl search_term

Output:

business-isp/lib/Business/ISP/Ledger.pm: invoice_number _gledger_write_legacy business-isp/lib/Business/ISP/User.pm: add_notes business-isp/lib/Business/ISP/Conversion.pm: plans_inf_to_db business-isp/lib/Business/ISP/Reports.pm: renewal_notices business-isp/lib/Business/ISP/GUI/Accounting.pm: home process_purchase perform_find show_plan setup confirm_purchase

Code:

#!/usr/bin/perl use warnings; use strict; use 5.18.0; use Devel::Examine::Subs; use File::Find; my $des = Devel::Examine::Subs->new(); my $search = $ARGV[0]; find({ wanted => \&check_subs, no_chdir => 1 }, 'business-isp/lib/Business/ISP' ); sub check_subs { if (! -f or ! /(?:\.pm|\.pl)$/){ return; } my $file = "$File::Find::name"; my @has = $des->has({file => $file, search => $search}); return if ! @has; say "\n$file:" ; say "\t$_" for @has; }

-stevieb

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found