Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ priorities and future plans.

## Work in progress

- Preserve reference lifetime when overloaded `++` and `--` fall back to arithmetic (#1901).
- Parse forward-declared qualified classes as indirect constructors inside `new` methods (#1899).

- Match Perl `Encode` aliases for ANSI X3.4-1968, HZ-GB-2312, and ISO-8859-8-I, and include the BOM when encoding generic UTF-32 (#1897).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5722,8 +5722,7 @@ private RuntimeScalar preAutoIncrementWithoutWatcherNotification() {
result = ctx.tryOverload("(+", new RuntimeArray(this, scalarOne, scalarUndef));
if (result != null) {
// For fallback, + should NOT modify operand, so we handle assignment
this.type = result.type;
this.value = copyScalarPayload(result.type, result.value);
set(result);
return this;
}

Expand Down Expand Up @@ -6005,8 +6004,7 @@ private RuntimeScalar postAutoIncrementLarge() {
result = ctx.tryOverload("(+", new RuntimeArray(this, scalarOne, scalarUndef));
if (result != null) {
// For fallback, + should NOT modify operand, so we handle assignment
this.type = result.type;
this.value = copyScalarPayload(result.type, result.value);
set(result);
return old;
}

Expand Down Expand Up @@ -6157,8 +6155,7 @@ private RuntimeScalar preAutoDecrementWithoutWatcherNotification() {
result = ctx.tryOverload("(-", new RuntimeArray(this, scalarOne, scalarUndef));
if (result != null) {
// For fallback, - should NOT modify operand, so we handle assignment
this.type = result.type;
this.value = copyScalarPayload(result.type, result.value);
set(result);
return this;
}
}
Expand Down Expand Up @@ -6316,8 +6313,7 @@ private RuntimeScalar postAutoDecrementWithoutWatcherNotification() {
result = ctx.tryOverload("(-", new RuntimeArray(this, scalarOne, scalarUndef));
if (result != null) {
// For fallback, - should NOT modify operand, so we handle assignment
this.type = result.type;
this.value = copyScalarPayload(result.type, result.value);
set(result);
return old;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use strict;
use warnings;
no warnings 'numeric';
use Test::More;

{
package Local::FormattedDate;
use Scalar::Util qw(refaddr);
our %FORMATS;

use overload
'+' => sub { _offset($_[0], $_[1]) },
'-' => sub { _offset($_[0], -$_[1]) },
'""' => sub {
my ($self) = @_;
return sprintf $FORMATS{refaddr($self)}, $$self;
},
fallback => 1;

sub _offset {
my ($self, $delta) = @_;
my $result = bless \($$self + $delta), ref($self);
$FORMATS{refaddr($result)} = $FORMATS{refaddr($self)};
return $result;
}

sub set_format { $FORMATS{refaddr($_[0])} = $_[1] }

sub DESTROY { delete $FORMATS{refaddr($_[0])} }
}

my $value = 20261101;
my $date = bless \$value, 'Local::FormattedDate';
$date->set_format('custom:%d');

++ $date;
is("$date", 'custom:20261102', 'preincrement keeps state on the overloaded result');

-- $date;
is("$date", 'custom:20261101', 'predecrement keeps state on the overloaded result');

$date++;
is("$date", 'custom:20261102', 'postincrement keeps state on the overloaded result');

$date--;
is("$date", 'custom:20261101', 'postdecrement keeps state on the overloaded result');

done_testing();
Loading