mlewando has asked for the wisdom of the Perl Monks concerning the following question:
To something along the line of:sub WriteLine { my $self = shift; my $it = $self->OStream->WriteLine($_[0]); $self->Trace(_CallerStr($it)); return $it; }; sub Select { my $self = shift; my $it = $self->OStream->Select($_[0]); $self->Trace(_CallerStr($it)); return $it; }; sub Add { my $self = shift; my $it = $self->OStream->Add($_[0]); $self->Trace(_CallerStr($it)); return $it; };
sub <Call> { my $self = shift; my $it = $self->OStream-><Call>($_[0]); $self->Trace(_CallerStr($it)); return $it; };
Such that, I can use $Wrapper->Remove($item) and the function '<Call>' is executed and <Call> is substituted with 'Remove'. I can only think of using callbacks and a dispatcher but it seems like I would still have to generate all of the callback subs which I kind of want to avoid. Don't get me wrong it's not like copy/pasting is the end of the world, but why copy paste redundancy if there exists a method where I can almost template it? I would also like the simplicity in $X->Y->Z($item) and not have to work a dispatch and sub-call, which I have done before by passing a dispatch function a 'function name' like:
if(defined $dev_desc{$tcp_data->Dispatch((USF::Modbus::Modbus::CB_NUMBERS))})But then I end up checking function name and data followed by execution, whereas I want something like (kind of a bad example but the point is there):
if(defined $dev_desc{$tcp_data->Dispatch->Numbers($tcp_data->Value)})Maybe an overload? But then I would still have to have overload functions where all I really want to do is have it intuitively fill in the blacks since all of the functions will be doing the same thing since it is essentially a proxy class with subroutine tracing built-in for logging/debugging traceability. If it's not possible then oh well I guess, I just feel like there should be a better solution to excessive redundancy (especially when I am already using a proxy). I also feel it isn't entirely a thing since it would be a nightmare for the interpreter.
Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Generic/Variable/Dynamic Subroutines? (Not a redefine)
by haukex (Archbishop) on Aug 18, 2017 at 19:27 UTC | |
Re: Generic/Variable/Dynamic Subroutines? (Not a redefine)
by shmem (Chancellor) on Aug 18, 2017 at 19:28 UTC | |
Re: Generic/Variable/Dynamic Subroutines? (Not a redefine)
by LanX (Saint) on Aug 19, 2017 at 19:00 UTC | |
by mlewando (Initiate) on Aug 21, 2017 at 17:10 UTC | |
by LanX (Saint) on Aug 21, 2017 at 17:17 UTC | |
by shmem (Chancellor) on Aug 21, 2017 at 18:08 UTC | |
by LanX (Saint) on Aug 21, 2017 at 18:19 UTC | |
|