Skip to content

Commit

Permalink
convert some method arg handling from shift to unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Aug 23, 2024
1 parent 6809959 commit 14d45d8
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/PPI/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -714,40 +714,40 @@ sub __position {

# Insert one or more elements before a child
sub __insert_before_child {
my $self = shift;
my $key = refaddr shift;
my ( $self, $child, @insertions ) = @_;
my $key = refaddr $child;
my $p = List::Util::first {
refaddr $self->{children}[$_] == $key
} 0..$#{$self->{children}};
foreach ( @_ ) {
foreach ( @insertions ) {
Scalar::Util::weaken(
$_PARENT{refaddr $_} = $self
);
}
splice( @{$self->{children}}, $p, 0, @_ );
splice( @{$self->{children}}, $p, 0, @insertions );
1;
}

# Insert one or more elements after a child
sub __insert_after_child {
my $self = shift;
my $key = refaddr shift;
my ( $self, $child, @insertions ) = @_;
my $key = refaddr $child;
my $p = List::Util::first {
refaddr $self->{children}[$_] == $key
} 0..$#{$self->{children}};
foreach ( @_ ) {
foreach ( @insertions ) {
Scalar::Util::weaken(
$_PARENT{refaddr $_} = $self
);
}
splice( @{$self->{children}}, $p + 1, 0, @_ );
splice( @{$self->{children}}, $p + 1, 0, @insertions );
1;
}

# Replace a child
sub __replace_child {
my $self = shift;
my $old_child_addr = refaddr shift;
my ( $self, $old_child, @replacements ) = @_;
my $old_child_addr = refaddr $old_child;

# Cache parent of new children
my $old_child_index = List::Util::first {
Expand All @@ -756,14 +756,14 @@ sub __replace_child {

return undef if !defined $old_child_index;

foreach ( @_ ) {
foreach ( @replacements ) {
Scalar::Util::weaken(
$_PARENT{refaddr $_} = $self
);
}

# Replace old child with new children
splice( @{$self->{children}}, $old_child_index, 1, @_ );
splice( @{$self->{children}}, $old_child_index, 1, @replacements );

# Uncache parent of old child
delete $_PARENT{$old_child_addr};
Expand Down

0 comments on commit 14d45d8

Please sign in to comment.