in reply to What does the SHIFT bit do in a constructor

Your variable name say it all ;-)
It's the class/package name used with bless...

From perltoot :

To do this, all we have to do is check whether what was passed in was a reference or not. If so, we were invoked as an object method, and we need to extract the package (class) using the ref() function. If not, we just use the string passed in as the package name for blessing our referent.
sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{NAME} = undef; $self->{AGE} = undef; $self->{PEERS} = []; bless ($self, $class); return $self; }
It's done this way to permit inheritance...

Check perlboot for other (good) informations...

"Only Bad Coders Code Badly In Perl" (OBC2BIP)

Replies are listed 'Best First'.
Re (tilly) 2: What does the SHIFT bit do in a constructor
by tilly (Archbishop) on May 25, 2001 at 23:20 UTC
    Note that many people who have used OO programming for a very long time (starting with merlyn who has been using it since the early 80's) detest the use of ref there. Object methods and instance methods are different, no need to confuse them. That said I would write the above as:
    sub new { my $self = bless {}, shift; @$self{'PEERS', 'NAME', 'AGE'} = []; return $self; }
    which looks cleaner to my eyes. YMMV.

      In the abstract, I understand and somewhat agree with this criticism. But when you get into a specific object implementation, it often makes a great deal of sense.

      It comes down to whether the reader will clearly understand what: my $other= $object->new(); is meant to do. I find that for many specific object implementations, this is a quite natural idiom. So I agree that you should think about what that idiom is supposed to mean in your specific class before you decide either way!

      A similar criticism is that you should not name your constructors "new" either. Again, I agree with this in the abstract but find that when I get down to real cases, the criticism usually doesn't apply. For many objects, trying to find a more descriptive name for the constructor that describes how I want to go about creating the object just adds confusion.

              - tye (but my friends call me "Tye")