in reply to Table::Extract unblessed reference

I wonder if this line (line 74 of the module source) has anything to do with it:
sub new { my $that = shift; my $class = ref($that) || $that; #<-- (line 74) # [snip] bless $self, $class; }
I've never seen a class name determined that way before. ref($that) will return the type of reference if $that is a reference. That doesn't seem right, does it? I'm thinking maybe the module author meant to use a conditional operator there instead.

Replies are listed 'Best First'.
Re^2: Table::Extract unblessed reference
by chromatic (Archbishop) on Jul 29, 2005 at 23:24 UTC

    If $that is not a reference, ref returns a false value and the constructor uses the value of $that literally as the class name. In effect, you can call new() as a class or an object method and receive a new object back.

    I consider that a bad design decision, but good luck trying to convince people that, when the documentation recommends it....

      I consider that a bad design decision, but good luck trying to convince people that, when the documentation recommends it....

      Actually, I agree with this. That little snippet is an artifact from back when I wrote the original code. Since then I've changed my mind about that trick.

      Matt