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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:15:54+00:00 2026-05-14T07:15:54+00:00

I have a base class like this: package MyClass; use vars qw/$ME list of

  • 0

I have a base class like this:

package MyClass;

use vars qw/$ME list of vars/;
use Exporter;
@ISA = qw/Exporter/;
@EXPORT_OK = qw/ many variables & functions/;
%EXPORT_TAGS = (all => \@EXPORT_OK );

sub my_method {

}
sub other_methods etc {

}

--- more code---

I want to subclass MyClass, but only for one method.

package MySubclass;

use MyClass;
use vars qw/@ISA/;
@ISA = 'MyClass';

sub my_method {

--- new method

}

And I want to call this MySubclass like I would the original MyClass, and still have access to all of the variables and functions from Exporter. However I am having problems getting the Exporter variables from the original class, MyClass, to export correctly. Do I need to run Exporter again inside the subclass? That seems redundant and unclear.

Example file:

#!/usr/bin/perl

use MySubclass qw/$ME/;

-- rest of code

But I get compile errors when I try to import the $ME variable. Any suggestions?

  • 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-14T07:15:54+00:00Added an answer on May 14, 2026 at 7:15 am

    You’re not actually inheriting MySubclass from MyClass at all — MySubClass is a user of MyClass. What you’re doing is overriding a bit of behaviour from MyClass, but you will only confuse yourself if you think of this as inheritance, because it isn’t (for example: where is your constructor?) I couldn’t figure out what you were trying to do until I ignored everything the code was doing and just read your description of what you want to have happen.

    Okay, so you have a class which imports some symbols – some functions, and some variables:

    package MyClass;
    use strict;
    use warnings;
    
    use Exporter 'import';    # gives you Exporter's import() method directly
    our @EXPORT_OK = qw/ many variables & functions/;
    our %EXPORT_TAGS = (all => \@EXPORT_OK );
    our ($ME, $list, $of, $vars);
    
    sub my_func {
    
    }
    sub other_func {
    
    }
    1;
    

    and then you come along and write a class which imports everything from MyClass, imports it all back out again, but swaps out one function for another one:

    package MyBetterclass;
    use strict;
    use warnings;
    use Exporter 'import';    # gives you Exporter's import() method directly
    our @EXPORT_OK = qw/ many variables & functions /;
    our %EXPORT_TAGS = (all => \@EXPORT_OK );
    use MyClass ':all';
    
    sub my_func {
        # new definition   
    }
    1;
    

    That’s it! Note that I enabled strict checking and warnings, and changed the names of the “methods” that are actually functions.
    Additionally, I did not use use vars (the documentation says it’s obsolete, so that’s a big red flag if you still want to use it without understanding its mechanics).

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

Sidebar

Related Questions

I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
Let's say I have an abstract base class that looks like this: class StellarObject(BaseModel):
I have a base class vehicle and some children classes like car, motorbike etc..
I have a tree of active record objects, something like: class Part < ActiveRecord::Base
I have a base class object array into which I have typecasted many different
I have a package of plug-in style modules. It looks like this: /Plugins /Plugins/__init__.py
If I have a generic class like this: public class Repository<T> { public string
I have implemented a templated buffer class like this: template <class T, class Impl>
I have a holder movieclip, its base class is foo. package { import flash.display.MovieClip;
I have a DBIC schema, where all the classes use a common base 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.