2xlp has asked for the wisdom of the Perl Monks concerning the following question:

I have 3 websites that have been running off a proprietary mod_perl2 framework that I've been trying to standardize for eventual public distribution. ( and to answer some questions preemptively: I started work on this long before catalyst or jifty were around , when tt and mason were the only viable options )

Right now I'm trying to standardize a behavior in the dispatch class. I'm hoping someone can offer advice

The framework works pretty much like this:

Each instance of MyApp::PageController (ie: MyApp1 , MyApp2 ) has the following 2 vars:

Modules can register themselves on startup to allow uploads or a 'fatter' max upload than default via a Getter+Setter method , and the first stage of every MyApp handler call is to build an ApacheRequest object using the information stored in the MyApp::PageController class.

My problem is:

Under the current design of the framework, the modules register against URI_enabled_fat/URI_enabled_upload as class variables, not object instance variables. Because of that, I have the getter/setter methods implemented in each MyApp::PageController class -- not in P2XLP::PageController-- I also have the function to build an ApacheRequest object in there too.

The issue is with migrating the getter/setters and builder into P2XLP::PageController -- I can't imagine any other way of accomplishing this other than an eval, which I try to avoid at all costs.

Can someone suggest a way to move the getter/setter/builder into the P_2XLP namespace, and still have it access the MyApp namespace for vars and calls efficiently and without using evals ?

Basically, I want to keep roughly this syntax:

package MyApp; my $aprObject= MyApp::PageController::build_apr_object(); package MyApp::Page::PhotoUpload; MyApp::PageController::register_enable_upload('/my/photos/upload'); MyApp::PageController::register_enable_fat('/my/photos/upload',100_000 +);
but i want the functions and vars to be maintained here:
package MyApp::PageController; our (%URI_enabled_fat , %URI_enabled_upload); package P_2XLP::PageController; sub register_enable_upload{}; sub register_enable_fat{}; sub build_apr_object{};

I have no idea how to accomplish this in a logical way -- or even if its possible. what I'm trying to do is very counter-intuitive to many 'better' programming paradigms. Unfortunately, my design requirement is to maintain the variables as package/class variables within the subclass, while maintaing the functions in the super class.

If anyone can offer suggestions, I'd be very appreciative.

Replies are listed 'Best First'.
Re: Need help migrating functionality from subclass to super class
by kyle (Abbot) on May 03, 2007 at 15:33 UTC

    I'm not sure I'm completely clear on what you're looking for. In particular, I think your last <code> block probably ought to be different since you declare the same package twice.

    One thing you could do is have the subclass pass references to its our variables to the superclass at some point. If you don't want to change anything in the subclass, maybe some part of the superclass could use caller to see where a call is coming from, but I don't know that you can get access to the subclass's variables that way.

    As I was reading, I kept thinking maybe you could tie those variables to some package that would do whatever twisty thing you want to do. Something like:

    package MyApp::Mistake; my $destination; sub TIEHASH { ... } sub STORE { my ($self, $key, $value) = @_; $destination->{$key} = $value; } sub set_destination { $destination = $_[1] } package MyApp::PageController; my %URI_enabled; MyApp::Mistake->set_destination( \%URI_enabled );

    That could maybe work, but it seems like a lot of voodoo.