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 6823163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:45:00+00:00 2026-05-26T21:45:00+00:00

When you run perl -e "Bla->new" , you get this well-known error: Can’t locate

  • 0

When you run perl -e "Bla->new", you get this well-known error:

Can't locate object method "new" via package "Bla"
(perhaps you forgot to load "Bla"?)

Happened in a Perl server process the other day due to an oversight of mine. There are multiple scripts, and most of them have the proper use statements in place. But there was one script that was doing Bla->new in sub blub at line 123 but missing a use Bla at the top, and when it was hit by a click without any of the other scripts using Bla having been loaded by the server process before, then bang!

Testing the script in isolation would be the obvious way to safeguard against this particular mistake, but alas the code is dependent upon a humungous environment. Do you know of another way to safeguard against this oversight?

Here’s one example how PPI (despite its merits) is limited in its view on Perl:

use strict;
use HTTP::Request::Common;

my $req = GET 'http://www.example.com';
$req->headers->push_header( Bla => time );

my $au=Auweia->new;

__END__
PPI::Token::Symbol          '$req'
PPI::Token::Operator        '->'
PPI::Token::Word            'headers'
PPI::Token::Operator        '->'
PPI::Token::Word            'push_header'

PPI::Token::Symbol          '$au'
PPI::Token::Operator        '='
PPI::Token::Word            'Auweia'
PPI::Token::Operator        '->'
PPI::Token::Word            'new'

Setting the header and assigning the Auweia->new parse the same. So I’m not sure how you can build upon such a shaky foundation. I think the problem is that Auweia could also be a subroutine; perl.exe cannot tell until runtime.

Further Update

Okay, from @Schwern’s instructive comments below I learnt that PPI is just a tokenizer, and you can build upon it if you accept its limitations.

  • 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-26T21:45:00+00:00Added an answer on May 26, 2026 at 9:45 pm

    Testing is the only answer worth the effort. If the code contains mistakes like forgetting to load a class, it probably contains other mistakes. Whatever the obstacles, make it testable. Otherwise you’re patching a sieve.

    That said, you have two options. You can use Class::Autouse which will try to load a module if it isn’t already loaded. It’s handy, but because it affects the entire process it can have unintended effects.

    Or you can use PPI to scan your code and find all the class method calls. PPI::Dumper is very handy to understand how PPI sees Perl.

    use strict;
    use warnings;
    
    use PPI;
    use PPI::Dumper;
    
    my $file = shift;
    my $doc = PPI::Document->new($file);
    
    # How PPI sees a class method call.
    #    PPI::Token::Word      'Class'
    #    PPI::Token::Operator  '->'
    #    PPI::Token::Word      'method'
    $doc->find( sub {
        my($node, $class) = @_;
    
        # First we want a word
        return 0 unless $class->isa("PPI::Token::Word");
    
        # It's not a class, it's actually a method call.
        return 0 if $class->method_call;
    
        my $class_name = $class->literal;
    
        # Next to it is a -> operator
        my $op = $class->snext_sibling or return 0;
        return 0 unless $op->isa("PPI::Token::Operator") and $op->content eq '->';
    
        # And then another word which PPI identifies as a method call.
        my $method = $op->snext_sibling or return 0;
        return 0 unless $method->isa("PPI::Token::Word") and $method->method_call;
    
        my $method_name = $method->literal;
    
        printf "$class->$method_name seen at %s line %d.\n", $file, $class->line_number;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I run my perl CGI script without apache? This is for testing
I get this when I run the test, but as you can see, both
When I run perl , I get the warning: perl: warning: Setting locale failed.
maybe this is a stupid question but : i run perl 5.8.8 and i
I need to run two perl scripts from one in parallel. How can I
I'm trying to run this Perl script but it is not running as required.
Possible Duplicate: How can I run Perl system commands in the background? I have
I'm optimizing some frequently run Perl code (once per day per file). Do comments
In Perl, to run another Perl script from my script, or to run any
How do I run a Perl script on OS X?

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.