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

  • Home
  • SEARCH
  • 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 8787353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:52:14+00:00 2026-06-13T21:52:14+00:00

I have a Perl library that uses many objects of some (about 3 or

  • 0

I have a Perl library that uses many objects of some (about 3 or 4) classes during its operation.

In testing code, I’d like to ensure it isn’t too many (I’m not talking about memory leaks, I know how to check that). To this end, I thought I could count every object used and check the maximum used during the run on the test data. Then, I would compare the obtained number to some guess about how many objects the library should use.

However, I’ve got problems implementing this. I thought about two possible ways:

  • intercept Package::new and Package::DESTROY. However, this has a little catch that in that package, new doesn’t always return a new object. Sometimes, it uses a preexisting one (the objects are used as immutables, so it shouldn’t matter much). So I’d have to track each individual object to see if it existed before.

  • intercept Package::bless and Package::DESTROY. This should work, but seems a little unorthodox.

The question is, which of those ways is more likely to succeed (maybe what is commonly used in similar situations), and secondly, how would I even implement the second way (would I have to override Package::bless for all packages in question or only base classes etc.).

  • 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-06-13T21:52:15+00:00Added an answer on June 13, 2026 at 9:52 pm

    Try something like this (not tested):

    my $Package_objects = {};
    my $override_new = *Package::new{CODE};
    *Package::new = sub {
        my $self = $override_new->(@_);
        # Interpolate $self as string to get "HASH(0x12345)"; save package name
        $Package_objects->{ "$self" } = 'Package';
        return $self;
    };
    my $override_dest = *Package::DESTROY{CODE};
    *Package::DESTROY = sub {
        delete $Package_objects->{ "$_[0]" };
        $override_dest->(@_);
    };
    

    Probably this is most barbaric method, but must work without 3rd party modules 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Perl code that uses the system() function to call robocopy.exe, but it
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a script that uses modules that are external to the standard Perl
I have written a Perl XS wrapper for a C library consisting of about
I am currently learning Perl. I have Perl hash that contains references to hashes
I have a Perl script that takes user input and creates another script that
For some unfortunate reasons, I have to convert a proprietary and binary library from
I want to compile/install a Perl module that depends on a library that is
I have a large Perl script that is broken into several Perl libraries. In
I have an application in Perl that reads in HTML based mark up and

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.