Deal with @_ in signatured sub being experimental in Perl 5.36
This commit is contained in:
parent
459e5619a7
commit
c43764afbb
1 changed files with 10 additions and 2 deletions
|
@ -8,6 +8,14 @@ no warnings qw(experimental::signatures);
|
||||||
use Carp qw(carp croak);
|
use Carp qw(carp croak);
|
||||||
use RevBank::Users;
|
use RevBank::Users;
|
||||||
use List::Util ();
|
use List::Util ();
|
||||||
|
use Scalar::Util ();
|
||||||
|
|
||||||
|
# Workaround for @_ in signatured subs being experimental and controversial
|
||||||
|
my $NONE = \do { my $dummy };
|
||||||
|
sub _arg_provided($a) {
|
||||||
|
return 1 if not ref $a;
|
||||||
|
return Scalar::Util::refaddr($a) != Scalar::Util::refaddr($NONE)
|
||||||
|
}
|
||||||
|
|
||||||
sub new($class, $amount, $description, $attributes = {}) {
|
sub new($class, $amount, $description, $attributes = {}) {
|
||||||
$amount = RevBank::Amount->parse_string($amount) if not ref $amount;
|
$amount = RevBank::Amount->parse_string($amount) if not ref $amount;
|
||||||
|
@ -56,9 +64,9 @@ sub has_attribute($self, $key) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub attribute($self, $key, $new = undef) {
|
sub attribute($self, $key, $new = $NONE) {
|
||||||
my $ref = \$self->{attributes}->{$key};
|
my $ref = \$self->{attributes}->{$key};
|
||||||
$$ref = $new if @_ > 2;
|
$$ref = $new if _arg_provided($new);
|
||||||
return $$ref;
|
return $$ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue