Sunday, June 30, 2002, 5:57:23 PM, drieux wrote:
I don't know if it's just me, but I didn't really understand
what you're actually trying to achieve...
> Ok, so let's start with the simples stuff, I'm not God's
> brightest child - so I tend to try stuff, and argue with
> myself about whether or not a thing makes sense. Here is
> the basic problem.
> I need to have a base class
> FOO::BAR
> from which I will have a secondary class
> FOO::BAR::BAZ
> but for 'political Reasons' I want to have
> a new class that is 'derived' from FOO::BAR::BAZ
> but it needs to be 'hung' ass
> FOO::BAR::BOB
This sounds straightforward:
package FOO::BAR::BOB;
use base 'FOO::BAR::BAZ';
> So while muddling this affair I opted to do the following
> trick in the FOO::BAR class package:
> # our private defaults - things starting in a Capital
> # are 'public' elements, things in 'lower case', should
> # NOT be messed about by anyone but this module...
> # caveat emptor
But then you start mentioning public and private variables,
and other things.
> our %def =(
> Exposed_A => undef,
> Exposed_B => 666,
> Exposed_C => 'frodo',
> private_fd => undef,
> );
> #------------------------
> # So that we have a way to redefine our Values.
> sub redefine {
What is this "redefine" supposed to do?
> my $me = shift;
> if ( @_ % 2 ) {
> $me->{'Exposed_A'} = shift;
> # only suppose to hand me the Single Arg...
> die "Odd Number of args passed to redefine: @_ \n" if @_;
> } else {
> # this seems to be required to allow sub_classing
> # hence we can not get away with some of the dope we have
>done
> my %hash = (@_);
> while( my ($k,$v) = each %hash ) {
> if ( $k eq 'fd' ) {
> me->CloseOut() if defined($me->{private_fd});
> $v = undef unless ( ref($v) eq "PRIVATE::TYPE");
> }
And what's a PRIVATE::TYPE?
Perhaps some more explanation about what you're trying to
do here would be useful.
--
Best Regards,
Daniel [EMAIL PROTECTED]
> $me->{$k} = $v ;
> }
> }
> $me->{private_fd} = new PRIVATE::TYPE
> unless defined $me->{private_fd};
> } # end of redefine
> #------------------------
> # so that the NEW remains almost as virgin as possible
> sub _init {
> my $me = shift;
> # load our defaults
> while( my ($k,$v) = each %def) {
> $me->{$k} = $v ;
> }
> $me->redefine(@_) if @_;
> # so that we always have a New One of these
> $me->{private_fd} = new PRIVATE::TYPE
> unless defined $me->{private_fd};
> } # end of _init
> #------------------------
> # So that we have our _init do our initializing
> sub new {
> my $type = shift;
> my $self = {};
> my $class = ref($type) || $type ;
> bless $self, $class ;
> #
> # this may bother some with the subsequent sub_classing
> #
> $self->_init(@_);
> $self;
> } # end New
> The new is basically stock out of the manual - save for my choice
> to allow an '_init()' - that is from the old naming convention,
> one "_" is an application specific thingie - in this case one of
> our 'private' methods - but since I may need to pass thru re-definitions,
> why not have a 'redefine' - where I can stuff all of MY personal
> requirements for how this class should be doing it.....
> I think I should 'expose' the redefine() method - so that other sub_classes
> can use it... in this sense, point to it in the POD - since I really can
> not think of a way to expressly prevent them from using it. I found that
> having this redefine() allows me 'back door' updates in my
> own methods where I use tricks like
> sub do_me_now {
> my $self = shift;
> $self->redefine(@_) if @_;
> .....
> }
> So far - I think I am well within Kosher, since in the
> FOO::BAR::BAZ I do the old
> package FOO::BAR::BAZ;
> ....
> our @ISA = qw(FOO::BAR);
> steal the very same 'new' method - cut and paste, and out
> and away we go.... BadaBoom, badaBing - the new in this class
> updates the stuff I want to have initialized in the base class
> as well.... So Far - no major worry. I mean not a lot of additional
> typing so far - we add a few more basic methods of this BAZ stuff
> that are uniq from the FOO::BAR style and all is kosher. { at
> least the code works. }
> So we gin up the FOO::BAR::BOB package - and skate it along as
> being one of the
> package FOO::BAR::BOB;
> ....
> our @ISA = qw(FOO::BAR::BAZ);
> and what is sauce for the GOOSE, is sauce for the gander.... so
> we put in our own collection of Bob's def Jam Players -
> our %def =(
> Exposed_A => 'funnyThing',
> BOB_A => 'special Sauce',
> BOB_B => 'Where The Dinasaour',
> private_a => undef,
> );
> # yes - that is the Exposed_A we want to by default reset
> # in our base_class.... the Other's are MINE!!!
> #------------------------
> # So that we have our _init do our initializing
> sub new {
> my $type = shift;
> my $self = {};
> my $class = ref($type) || $type ;
> bless $self, $class ;
> #
> # this may bother some with the subsequent sub_classing
> #
> $self->_init(%def,@_);
> $self;
> } # end New
> As you can see - this new is like the other news... except that
> we have some 'defaults' we want to pass in "first" - that can
> be over-ridden by the endUser's own set....
> So It works... I know... I have tested it.... I'm just a bit
> nervous about whether or not this is a Kosher Approach....
> What are the Gotcha's I haven't thought about in this process????
> ciao
> drieux
> ---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]