Description: Data::Alias is broken on perl >= 5.24
 The Data::Alias module itself explains:
 .
 > you should prefer to use the core facility rather than use this
 > module. If you are already using this module and are now using a
 > sufficiently recent Perl, you should attempt to migrate to the core
 > facility
 .
 The idea is to use core refaliasing when available and Data::Alias
 otherwise.
 .
 This patch is a merge of the 2 commits of the pull request.
Author: Daniel Dehennin <daniel.dehennin@baby-gnu.org>
Origin: https://github.com/tobyink/p5-kavorka/pull/19
Bug: https://github.com/tobyink/p5-kavorka/issues/18
Bug-Debian: https://bugs.debian.org/834800
Last-Update: 2016-12-15

--- a/lib/Kavorka/Signature.pm
+++ b/lib/Kavorka/Signature.pm
@@ -19,6 +19,8 @@
 use Moo;
 use namespace::sweep;
 
+use constant HAS_REFALIASING => ($] >= 5.022);
+
 has package           => (is => 'ro');
 has _is_dummy         => (is => 'ro');
 has params            => (is => 'ro',  default => sub { +[] });
@@ -276,13 +278,45 @@
 	or $slurpy && $slurpy->name =~ /\A\%/
 	or $slurpy && $slurpy->name =~ /\A\$/ && $slurpy->type->is_a_type_of(Types::Standard::HashRef()))
 	{
-		require Data::Alias;
 		my $ix  = 1 + $self->last_position;
-		my $str = sprintf(
+		my $str;
+		if (HAS_REFALIASING) {
+			my $format = <<'EOF';
+local %%_;
+{
+	use Carp qw(croak);
+	use experimental 'refaliasing';
+
+	if ($#_==%d && ref($_[%d]) eq q(HASH)) {
+		\%%_ = \%%{$_[%d]};
+	}
+	else {
+		# Make a hash reference from array refalias does not work
+		# Manual build
+		my $slice_length = ($#_ + 1 - %d);
+		if ($slice_length %% 2 != 0) {
+			# Seems to be what t/10positional.t wants
+			croak("Odd number of elements in anonymous hash");
+		}
+		my $i = %d;
+		while ($i <= $#_) {
+			my $key = $_[$i];
+			\$_{$key} = \$_[$i+1];
+			$i += 2;
+		}
+	}
+};
+EOF
+			$str = sprintf($format,($ix) x 5,);
+		}
+		else {
+			require Data::Alias;
+			$str = sprintf(
 			'local %%_; { use warnings FATAL => qw(all); Data::Alias::alias(%%_ = ($#_==%d && ref($_[%d]) eq q(HASH)) ? %%{$_[%d]} : @_[ %d .. $#_ ]) };',
 			($ix) x 4,
 		);
-		
+		}
+
 		unless ($slurpy or $self->yadayada)
 		{
 			my @allowed_names = map +($_=>1), map @{$_->named_names}, $self->named_params;
--- a/lib/Kavorka/TraitFor/Parameter/alias.pm
+++ b/lib/Kavorka/TraitFor/Parameter/alias.pm
@@ -9,6 +9,8 @@
 
 use Moo::Role;
 
+use constant HAS_REFALIASING => ($] >= 5.022);
+
 around _injection_assignment => sub
 {
 	my $next = shift;
@@ -17,8 +19,21 @@
 	
 	if ($self->kind eq 'my')
 	{
-		require Data::Alias;
-		return sprintf('Data::Alias::alias(my %s = do { %s });', $var, $val);
+		my $format;
+		if (HAS_REFALIASING) {
+			$format = <<'EOF';
+my %s;
+{
+	use experimental 'refaliasing';
+	\%s = \do { %s };
+};
+EOF
+			return sprintf($format, ($var) x 2, $val);
+		}
+		else {
+			require Data::Alias;
+			return sprintf('Data::Alias::alias(my %s = do { %s });', $var, $val);
+		}
 	}
 	elsif ($self->kind eq 'our')
 	{
--- a/lib/Kavorka/TraitFor/Parameter/ref_alias.pm
+++ b/lib/Kavorka/TraitFor/Parameter/ref_alias.pm
@@ -9,6 +9,8 @@
 
 use Moo::Role;
 
+use constant HAS_REFALIASING => ($] >= 5.022);
+
 around _injection_assignment => sub
 {
 	my $next = shift;
@@ -17,8 +19,21 @@
 	
 	if ($self->kind eq 'my')
 	{
-		require Data::Alias;
-		return sprintf('Data::Alias::alias(my %s = %s{ +do { %s } });', $var, $self->sigil, $val);
+		my $format;
+		if (HAS_REFALIASING) {
+			$format = <<'EOF';
+my %s;
+{
+	use experimental 'refaliasing';
+	\%s = \%s{ +do { %s } };
+};
+EOF
+			return sprintf($format, ($var) x 2, $self->sigil, $val);
+		}
+		else {
+			require Data::Alias;
+			return sprintf('Data::Alias::alias(my %s = %s{ +do { %s } });', $var, $self->sigil, $val);
+		}
 	}
 	elsif ($self->kind eq 'our')
 	{
