doy / package-stash-xs

faster and more correct implementation of the Package::Stash API
4 stars 3 forks source link

Behavioural difference between P::S::XS and P::S::PP #9

Open melak opened 7 years ago

melak commented 7 years ago

Consider the following:

package PkgA;

use Moose;

use overload
        '""'            => \&_as_string,
;

use MooseX::NonMoose;

has 'attr' => ( is => 'rw', isa => 'Str', default => 'asdf' );
sub _as_string { return shift->attr };

1;

MooseX::NonMoose will at one point make use of Package::Stash.

With Package::Stash::PP, things work as expected. With Package::Stash::XS installed, not so much:

$ perl -I. -e 'use PkgA'
Subroutine _as_string redefined at PkgA.pm line 12.

However, if I change the value bit of the overload argument to be a scalar (i.e. method name instead of a subref), Package::Stash::XS works too:

package PkgA;

use Moose;

use overload
        '""'            => '_as_string',
;

use MooseX::NonMoose;

has 'attr' => ( is => 'rw', isa => 'Str', default => 'asdf' );
sub _as_string { return shift->attr };

1;
$ perl -I. -e 'use PkgA'
$

Further however, if I move use MooseX::NonMoose such that it comes before the overload pragma, subref notation works with Package::Stash::XS:

package PkgA;

use Moose;
use MooseX::NonMoose;

use overload
        '""'            => \&_as_string,
;

has 'attr' => ( is => 'rw', isa => 'Str', default => 'asdf' );
sub _as_string { return shift->attr };

1;
$ perl -I. -e 'use PkgA'
$

Package::Stash::PP works regardless of anything, as far as I can tell.

It would seem that if Package::Stash with the XS backend gets imported after the overload pragma is used, and where overload happens to be using subref notation, things go sideways.

Reliably reproducible on

  1. FreeBSD/amd64 with Perl 5.24.1, Moose 2.2004, Package::Stash::XS 0.28
  2. Linux/x86_64 (Red Hat) with Perl 5.20.1, Moose 2.1806 and 2.1403, Package::Stash::XS 0.28
  3. Linux/x86_64 (Ubuntu) with Perl 5.22.1, Moose 2.1604, Package::Stash::XS 0.28

i.e. Package::Stash::XS 0.28 is seemingly the only common denominator.

karenetheridge commented 7 years ago

we should probably move this distribution to github.com/moose/.

melak commented 7 years ago

I have no idea what this means.