Skip Menu |

This queue is for tickets about the MooX-TypeTiny CPAN distribution.

Report information
The Basics
Id: 131576
Status: open
Priority: 0/
Queue: MooX-TypeTiny

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.001004
Fixed in: (no value)



Subject: Ambient package for inline code should probably be Type::Tiny or some dummy package, and not the class which is being generated
## This generates a warning, but I've had other cases where ## similar things completely die... ## use strict; use warnings; BEGIN { $ENV{PERL_ONLY} = 1 }; # no XS package Foo { use Moo; use MooX::TypeTiny; use Types::Standard qw(HashRef Str); has _data => ( is => 'ro', isa => HashRef[Str], required => 1, init_arg => 'data', ); sub values { @_==1 or die 'too many parameters'; CORE::values %{shift->_data}; } sub keys { @_==1 or die 'too many parameters'; CORE::keys %{shift->_data}; } __PACKAGE__->meta->make_immutable; } my $obj = Foo->new(data => {foo => 42}); print "$_\n" for $obj->values; #require B::Deparse; #print B::Deparse->new->coderef2text(\&Foo::new);
On Sun Jan 26 21:01:20 2020, TOBYINK wrote: Show quoted text
> ## This generates a warning, but I've had other cases where > ## similar things completely die... > ## > > use strict; > use warnings; > > BEGIN { $ENV{PERL_ONLY} = 1 }; # no XS > > package Foo { > use Moo; > use MooX::TypeTiny; > use Types::Standard qw(HashRef Str); > has _data => ( > is => 'ro', > isa => HashRef[Str], > required => 1, > init_arg => 'data', > ); > sub values { > @_==1 or die 'too many parameters'; > CORE::values %{shift->_data}; > } > sub keys { > @_==1 or die 'too many parameters'; > CORE::keys %{shift->_data}; > } > __PACKAGE__->meta->make_immutable; > } > > my $obj = Foo->new(data => {foo => 42}); > > print "$_\n" for $obj->values; > > #require B::Deparse; > #print B::Deparse->new->coderef2text(\&Foo::new);
It appears that Type::Tiny 1.008004 was changed to specify a package, fixing this issue. I think that makes the most sense as a fix, so I'm inclined to close this with no change.
A similar issue can probably be produced with Moo and Sub::Quote and no Type::Tiny at all, though I haven't tried. The workaround in newer versions of Type::Tiny isn't 100% but it will cover most cases.
On Wed Apr 22 11:45:04 2020, TOBYINK wrote: Show quoted text
> A similar issue can probably be produced with Moo and Sub::Quote and > no Type::Tiny at all, though I haven't tried. > > The workaround in newer versions of Type::Tiny isn't 100% but it will > cover most cases.
Sub::Quote will take its context package from where the sub was created. It's intentional that you would be able to call things from that package without qualifying them. If you need to be certain that you are using the core functions, calling them with CORE:: is appropriate.