in reply to enabling OO and non-OO access to the same module using a hash reference

Thanks for all suggestions, especially from Ikegami which led me to write the code under. There is also the possibility of using builtin caller(), but supporting these four ways to call seems more than enough flexibility and there is also the consideration of performance given that the particular method I am dealing with recurses millions of times for large inputs.
sub method { my $self = $_[0]; # leave it alone for obj/hashref unless( ref( $self ) || !$#_ ) { # else is immed. hash or # list of pairs my %opt = @_; $self = \%opt; } # now $self can be processed as a hashref whichever # of the four calling styles was used }

-M

Free your mind

  • Comment on Re: enabling OO and non-OO access to the same module using a hash reference
  • Download Code