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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:13:35+00:00 2026-05-15T08:13:35+00:00

package a::b::c:d my $res = a::b::c:e->new(); # i am doing like this # is

  • 0
package a::b::c:d

my $res =  a::b::c:e->new(); # i am doing like this
# is there any othere to do this

sub new {
...
 my $self = { 
     #result = a::b::c:e->new();
  }
}

sub test {
}

sub test2 {
}


1;

package a::b::c:e

sub new {
...
}

sub testresult {
}
1;

My question is:

  • how to initalize the e module in d in new itself rather creating every function and

  • how to use that to store some results into e:testresult

  • 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-15T08:13:36+00:00Added an answer on May 15, 2026 at 8:13 am

    There are two strategies — either examine the symbol table to initialize on creation, or make use of AUTOLOAD and test with can. AUTOLOAD can be messier as you have to deal with the case where the method isn’t there:

    sub AUTOLOAD {
        my $self = shift;
    
        my $method = $AUTOLOAD;
        $method =~ s/.*://;   # strip package name
    
        if ( $self->{'result'}->can($method) ) {
            return $self->{'result'}->$method(@_);
        } else {
            croak "Unknown method : $method";
        } 
    }  
    

    But the symbol table trick is brittle, as if they’re using inheritance, you won’t see the inherited methods without walking up @ISA, too. (and even if they’re not — they might start using inheritance in the future, which results in things breaking)

    …

    Typically, when you’re trying to copy another module’s interface, you’ve got a case of inheritance, so you might want to ask yourself what the relationship is between ::d and ::e :

    • a::b::c::d is an a::b::c::e
    • a::b::c::d uses a::b::c::e

    If it’s an is-a relationship, it’s typically better suited to inheritance (although you might have wrappers around each of the methods, and still need to go through this whole exercise anyway). If it’s a uses relationship, odds are you don’t want to inherit from every last method they have, and can just hard code a list (although, the list might change if the used class is updated)

    foreach my $method ( @list_of_methods_to_copy ) {
        *{$method} = sub {
            my $self = shift;
            return $self->{'results'}->$method(@_);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following express node.js app. It's using the 'redis' npm package. app.get(/test,function(req,res){
So I have this class here: package phil.droid.game; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle;
package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import javax.swing.*; public class
I'm looking at some code with this form: 1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList;
I'm new to Android app development and I would like to ask something. I
I have this code: package com.problemio; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View;
I tried to switch activities with this code: Intent i = new Intent(this, RegisterActivity.class);
There is a case that when a user presses the button a new TextView
I have the following code: package in.res.num.tapb.ui; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import
package com.fitaxis.test; import java.sql.SQLException; import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer;

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.