Skip to content
Snippets Groups Projects
Commit a216d482 authored by Jonas Smedegaard's avatar Jonas Smedegaard
Browse files

Fix dependency on Data::Alias: Add patch 1001 to use recent Perl instead of...

Fix dependency on Data::Alias: Add patch 1001 to use recent Perl instead of Data::Alias. (Build-)depend on recent perl favored over libdata-alias-perl. Closes: Bug#834800. Thanks to Daniel Dehennin.
parent 9744dae3
No related branches found
No related tags found
No related merge requests found
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')
{
0xxx: Grabbed from upstream development.
1xxx: Possibly relevant for upstream adoption.
2xxx: Only relevant for official Debian release.
1001_remove-data-alias-dependency.patch
......@@ -24,12 +24,13 @@ pkg = $(DEB_SOURCE_PACKAGE)
# Needed by upstream build and (always) at runtime
# * Recent Scalar::List::Utils needed for Sub::Util
perl-deps = data-alias exporter-tiny module-runtime padwalker
perl-deps = exporter-tiny module-runtime padwalker
perl-deps += parse-keyword return-type type-tiny
perl-deps += match-simple namespace-sweep
deps = $(patsubst %,$(comma) lib%-perl,$(perl-deps))
deps +=, libmoo-perl (>= 1.003001)
deps +=, libscalar-list-utils-perl (>= 1:1.40)
deps +=, perl (>= 5.22) | libdata-alias-perl
deps +=, perl (>= 5.14)
# Needed (often) at runtime
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment