package method with same name as perl builtin

perl

Solution

Note that no warnings at all are shown if subroutines are swapped:

sub unshift {
   my ($self, $node) = @_;
   push @{ $self->{nodes} } => $node;
}

sub push {
   my ($self, $node) = @_;
   push @{ $self->{nodes} } => $node;
}

... but there are two of them if `push` is pre-declared:

sub push;

sub unshift {
   my ($self, $node) = @_;
   push @{ $self->{nodes} } => $node;
}

sub push {
   my ($self, $node) = @_;
   push @{ $self->{nodes} } => $node;
}

# Ambiguous call resolved as CORE::push(), qualify as such or use & at line 10.
# Ambiguous call resolved as CORE::push(), qualify as such or use & at line 15.

My guess is that `push` name defined in the package is not basically taken into account until the whole subroutine's body is parsed. That's why within the subroutine this call isn't considered ambiguous.

Still, I'd rather prepend all the respective calls with `CORE::` prefix, as advised in perldiag.

To silently interpret [the subroutine name] as the Perl operator, use the `CORE::` prefix on the operator (e.g. `CORE::log($x)` ) or declare the subroutine to be an object method.

Problem

So I have module that has a method named `push`. Inside this method, I call perl's builtin `push` function. Now I have another method named `unshift`, and inside this method, again I call perl's builtin `push` function. ``` 1 package Deque; 2 3 ... 4 sub push { 5 my ($self, $node) = @_; 6 push @{ $self->{nodes} } => $node; 7 ... 8 } 9 10 sub unshift { 11 my ($self, $node) = @_; 12 push @{ $self->{nodes} } => $node; 13 ... 14 } ``` The program runs, but I get this warning `Ambiguous call resolved as CORE::push() ... line 12`. So I change line 12 to `CORE::push @{ $self->{nodes} } => $node`, and warning is gone. How come perl didn't warn me about line 6? Is there a better way to get rid of the warning? I can't change the method names.

Original source