Attempt to improve my original example:-
In ExtObj.pm:-
package ExtObj;
use vars qw ( $VERSION @ISA @EXPORT );
require Exporter;
@ISA = qw(Exporter);
@EXPORT = ( 'ExtObj' );
my $extobj;
sub import {
$extobj = new ExtObj::guts;
ExtObj->export_to_level(1, @_);
}#sub
sub ExtObj {
unless ( $extobj->{params}->{__orig_obj} ) {
$extobj->{params}->{__orig_obj} = shift;
}#unless
return $extobj;
}#sub
package ExtObj::guts;
sub new {
my $class = shift;
my $obj = {
params => {},
};
bless( $obj, $class );
return $obj;
}#sub
sub new_methods {
#code
}#sub
1;
In OrigObj.pm:-
package OrigObj;
use ExtObj;
my $OrigObj = {};
bless $OrigObj, OrigObj;
1;
ExtObj only exports one method of the same name to OrigObj. That method returns
an object of the ExtObj::guts class, which contains all the new_methods. Only
one instance of ExtObj::guts will ever be created and used. It's purely to
group similar methods together in sub objects, rather than having a huge object
with lots of methods.
I'm aiming for high cohesion and encapsulation, although methods of
ExtObj::guts will often have to access $OrigObj. The $extobj object of
ExtObj::guts, created in the ExtObj class can only be access through the
$OrigObj->ExtObj method and not directly through other $OrigObj methods.
(although saying that, I think I might need to wrap "my $extobj;" and the
following 2 subs in a block??).
Lyle
_______________________________________________
BristolBathPM mailing list
[email protected]
http://mailman.bristolbath.org/mailman/listinfo/bristolbathpm