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 them that I've found touch on how they work together.
I've been using Moose to make modules with attributes, and of course, it's useful to reference a module's attribute within said module. I've been told over and over again to use my $self = shift;
within a subroutine to assign the module's attributes to that variable. This makes sense and works, but when I'm also passing arguments to the subroutine, this process clearly takes the first element of the @ARGV
array and assigns it to $self
as well.
Can someone offer an explanation of how I can use shift to gain internal access to a module's attributes, while also passing in arguments in the @ARGV
array?
shift
defaults to@_
if called from inside a subroutine, or@ARGV
if called from top-level code. – Mouseear