Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 981535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:33:25+00:00 2026-05-16T04:33:25+00:00

I am refactoring a rather large body of code and a sort of esoteric

  • 0

I am refactoring a rather large body of code and a sort of esoteric question came to me while pondering where to go on with this. What this code needs in large parts is shortening of subs.

As such it would be very advantageous to point some sort of statistics collector at the directory, which would go through all the .pm, .cgi and .pl files, find all subs (i’m fine if it only gets the named ones) and gives me a table of all of them, along with their line count.

I gave PPI a cursory look, but could not find anything directly relevant, with some tools that might be appropiate, but rather complex to use.

Are there any easier modules that do something like this?

Failing that, how would you do this?

Edit:

Played around with PPI a bit and created a script that collects relevant statistics on a code base: http://gist.github.com/514512

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:33:26+00:00Added an answer on May 16, 2026 at 4:33 am
    my $document = PPI::Document->new($file);
    
    # Strip out comments and documentation                                                                                                                                              
    $document->prune('PPI::Token::Pod');
    $document->prune('PPI::Token::Comment');
    
    # Find all the named subroutines                                                                                                                                                    
    my $sub_nodes = $document->find(
        sub { $_[1]->isa('PPI::Statement::Sub') and $_[1]->name } );
    
    print map { sprintf "%s %s\n", $_->name, scalar split /\n/, $_->content } @$sub_nodes;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While refactoring code and ridding myself of all those #defines that we're now taught
While refactoring some old code I have stripped out a number of public methods
Whilst refactoring some code I came across some getter methods that returns a std::string.
This question is rather agnostic than related to a certain version control program. Assume
I'm familiar with refactoring fairly large code bases in C# and Java but Clojure
Whilst refactoring some old code I realised that a particular header file was full
When refactoring away some #defines I came across declarations similar to the following in
Whilst refactoring some legacy C++ code I found that I could potentially remove some
When refactoring classes and methods JDT doesn't change referenced resources, while it does when
So I'm refactoring my code to implement more OOP. I set up a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.