http://qs321.pair.com?node_id=648288


in reply to Re: getting 2 things done at once with Class::Base
in thread getting 2 things done at once with Class::Base

Whatever he is doing, I completely do _not_ understand it: He is returning a dereference of $errvar.
#--------------------------------------------------------------------- +--- # error() # error($msg, ...) # # May be called as a class or object method to set or retrieve the # package variable $ERROR (class method) or internal member # $self->{ _ERROR } (object method). The presence of parameters indic +ates # that the error value should be set. Undef is then returned. In the # abscence of parameters, the current error value is returned. #--------------------------------------------------------------------- +--- sub error { my $self = shift; my $errvar; { # get a reference to the object or package variable we're munging no strict qw( refs ); $errvar = ref $self ? \$self->{ _ERROR } : \${"$self\::ERROR"}; } if (@_) { # don't join if first arg is an object (may force stringification) $$errvar = ref($_[0]) ? shift : join('', @_); return undef; } else { return $$errvar; } }


Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality

Replies are listed 'Best First'.
Re^3: getting 2 things done at once with Class::Base (reading)
by tye (Sage) on Oct 31, 2007 at 15:43 UTC

    He returns undef unless no arguments were given. Not particularly complex code. Even documented:

    The presence of parameters indicates [...]. Undef is then returned. In the abscence of parameters­, the current error value is returned.

    His comments would be clearer if he changed one period into a semicolon, however.

    - tye