BMaximus has asked for the wisdom of the Perl Monks concerning the following question:
As a long time programer of Perl I feel that this is something that I shouldn't be doing and that there is a correct (and better) way of getting a subroutine's $self to behave as if it were a method of a class even though it's in a separate file. I feel like I am doing something completely wrong. What is the best way to fix this and have methods to a class organised and separated in to separate files? I have Damian Conway's Object oriented Perl but it really hasn't given me any ideas as to how to deal with this.package My::App; use strict; use warnings; use base qw(CGI::Application BLL::OtherPackage); sub setup { my $self = shift; $self->mode_param('section'); $self->start_mode('home'); $self->run_modes( 'here_sub' => 'here_sub', 'test_rm' => 'sub_in_other_file', ); } sub here_sub { my $self = shift; # no problems using self here } 1; ### Separate file package BLL::OtherPackage; use strict; use warnings; sub sub_in_other_file { my $self = shift; # $self would be what I expected if I didn't put this in # the 'use base' or @ISA for that matter. What an abuse. } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Class Inheritance Abuse. Best way to fix it?
by stvn (Monsignor) on Jun 05, 2006 at 21:11 UTC | |
|
Re: Class Inheritance Abuse. Best way to fix it?
by philcrow (Priest) on Jun 05, 2006 at 20:26 UTC | |
by girarde (Hermit) on Jun 05, 2006 at 21:21 UTC | |
by diotalevi (Canon) on Jun 05, 2006 at 21:45 UTC |