I\'m having a really hard time understanding the intersection of OO Perl and my $self = shift;
The documentation on these individual elements is great, but none of
In top level-code, shift()
is short for shift(@ARGV)
. @ARGV
contains the command-line arguments.
In a sub, shift()
is short for shift(@_)
. @_
contains the sub's arguments.
So my $self = shift;
is grabbing the sub's first argument. When calling a method, the invocant (what's left of the ->
) is passed as the first parameter. In other words,
$o->method(@a)
is similar to
my $sub = $o->can('method');
$sub->($o, @a);
In that example, my $self = shift;
will assign $o
to $self
.