Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 90774
Status: stalled
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: ZDM [...] cpan.org
Cc:
AdminCc:

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



Subject: possibility to turn off automtic warnings import
Please, add possibility to switch off automatic import of warnings pragma into the packages that use Moose. For example, we use following code: warnings->unimport(qw(experimental)) if $] >= 5.018; to disable experimental warnings in perl 5.18, but Moose override our settings when we use it.
Subject: Re: [rt.cpan.org #90774] possibility to turn off automtic warnings import
Date: Sun, 24 Nov 2013 08:55:18 -0800
To: Dmytro Zagashev via RT <bug-Moose [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
On Sun, Nov 24, 2013 at 11:47:23AM -0500, Dmytro Zagashev via RT wrote: Show quoted text
> Please, add possibility to switch off automatic import of warnings pragma into the packages that use Moose. > > For example, we use following code: > > warnings->unimport(qw(experimental)) if $] >= 5.018; > > to disable experimental warnings in perl 5.18, but Moose override our settings when we use it.
If you put that line after 'use Moose' in your module, it should work (you may need to put it in a BEGIN block, depending on the warning you want to disable).
I know, but we have own core package, which manage all our automatic imports and other configuration settings for packages that use it. This package always used first in all our huge number of modules.
On 2013-11-24 09:07:30, ZDM wrote: Show quoted text
> I know, but we have own core package, which manage all our automatic > imports and other configuration settings for packages that use it. > This package always used first in all our huge number of modules.
Can you be more specific with an example? I am having trouble seeing why your original code snippet is not adequate.
We have P::Core package: package P::Core; #configure console BEGIN { use English; use IO::Handle; use Encode(); use Encode::Locale(); use PerlIO::encoding; use Term::ANSIColor(); require Win32::Console::ANSI if $OSNAME =~ /MSWin/; die 'Console input encoding "' . $Encode::Locale::ENCODING_CONSOLE_IN . '"is not supported!' unless Encode::perlio_ok($Encode::Locale::ENCODING_CONSOLE_IN); local $PerlIO::encoding::fallback = Encode::FB_CROAK; binmode STDIN, ":encoding($Encode::Locale::ENCODING_CONSOLE_IN)"; die 'Console output encoding "' . $Encode::Locale::ENCODING_CONSOLE_OUT . '"is not supported!' unless Encode::perlio_ok($Encode::Locale::ENCODING_CONSOLE_OUT); local $PerlIO::encoding::fallback = Encode::FB_PERLQQ & ~Encode::LEAVE_SRC; binmode STDOUT, ":encoding($Encode::Locale::ENCODING_CONSOLE_OUT)"; binmode STDERR, ":encoding($Encode::Locale::ENCODING_CONSOLE_OUT)"; STDOUT->autoflush(1); STDERR->autoflush(1); #decode @ARGV Encode::Locale::decode_argv(Encode::FB_CROAK); } use v5.18.1; use utf8; use strict; use warnings ( qw(all), FATAL => qw(utf8), NONFATAL => qw() ); no if $] >= 5.018, warnings => qw(experimental); use feature qw(:all); use mro qw(c3); use autodie qw(:all); use threads ( exit => 'threads_only' ); use threads::shared; use namespace::sweep(); use Devel::Hook(); use B::Hooks::EndOfScope::XS(); use Hook::AfterRuntime(); sub import { my ( $class, @import ) = @_; my @tags = grep { substr( $_, 0, 1 ) ne q{-} } @import; my $caller = caller; utf8->import(); strict->import(); warnings->import( 'all', FATAL => qw(utf8), NONFATAL => qw() ); warnings->unimport(qw(experimental)) if $] >= 5.018; feature->import( ( version->new($])->normal ) =~ s/^v/:/r ); mro::set_mro( $caller, 'c3' ); P::Core::Config->import(@tags); P::Core::Constants->import(@tags); P::Core::Dump->import(@tags); P::Core::Exceptions->import(@tags); P::Core::Events->import(@tags); P::Core::Functions->import(@tags); P::Core::GO->import(@tags); P::Core::Log->import(@tags); P::Core::I18N->import(@tags); unless ( '-config' ~~ @_ ) { unless ( '-no-autoclean' ~~ @_ ) { namespace::sweep->import( -cleanee => $caller, -also => [] ); } if ( $caller eq 'main' ) { #main namespace #install CORE::CLI event caller unless ( '-no-cli' ~~ @import ) { Devel::Hook->push_INIT_hook( sub { P::throw_event('CORE::CLI'); } ); } #install CORE::RUNTIME event caller Devel::Hook->push_INIT_hook( sub { P::throw_event('CORE::RUNTIME'); } ); } else { #non-main namespace #cli for non-main namespace if ( '-cli' ~~ @import ) { push @P::Core::CLI::PACKAGES, $caller; } #apply exception and log roles to moose classes B::Hooks::EndOfScope::on_scope_end { if ( $caller->can('meta') && $caller->meta->isa('Moose::Meta::Class') ) { Moose::Util::apply_all_roles( $caller->meta, 'P::Core::Exceptions::Role' ); Moose::Util::apply_all_roles( $caller->meta, 'P::Core::Log::Role' ); } }; #make moose classes immutable unless ( '-no-immutable' ~~ @_ ) { Hook::AfterRuntime::after_runtime { if ( $caller->can('meta') && $caller->meta->isa('Moose::Meta::Class') ) { $caller->meta->make_immutable; } }; } } } #export autodie pragma unless ( '-no-autodie' ~~ @import ) { @_ = ( 'autodie', Fatal::LEXICAL_TAG, ':all' ); goto &Fatal::import; } return; } This package used first in all other our modules. As you can see it imports all needed functionality automatically, install hooks, etc... We use Moose and other modules after our core package used. And now Moose override our warning policy.
CC: ;
Subject: Re: [rt.cpan.org #90774] possibility to turn off automtic warnings import
Date: Sun, 24 Nov 2013 13:28:12 -0500
To: Dmytro Zagashev via RT <bug-Moose [...] rt.cpan.org>
From: Jesse Luehrs <doy [...] tozt.net>
In recent versions of perl, you can detect whether strict or warnings has been loaded manually (either enabled or disabled), so that "no strict; use 5.018" doesn't end up reenabling strict. We could probably hook into that in more recent versions of perl, to not do the reexporting of strict or warnings if they have already been loaded. -doy On Sun, Nov 24, 2013 at 01:09:12PM -0500, Dmytro Zagashev via RT wrote: Show quoted text
> Queue: Moose > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=90774 > > > We have P::Core package: > > package P::Core; > > #configure console > BEGIN { > use English; > use IO::Handle; > use Encode(); > use Encode::Locale(); > use PerlIO::encoding; > use Term::ANSIColor(); > require Win32::Console::ANSI if $OSNAME =~ /MSWin/; > > die 'Console input encoding "' . $Encode::Locale::ENCODING_CONSOLE_IN . '"is not supported!' unless Encode::perlio_ok($Encode::Locale::ENCODING_CONSOLE_IN); > local $PerlIO::encoding::fallback = Encode::FB_CROAK; > binmode STDIN, ":encoding($Encode::Locale::ENCODING_CONSOLE_IN)"; > > die 'Console output encoding "' . $Encode::Locale::ENCODING_CONSOLE_OUT . '"is not supported!' unless Encode::perlio_ok($Encode::Locale::ENCODING_CONSOLE_OUT); > local $PerlIO::encoding::fallback = Encode::FB_PERLQQ & ~Encode::LEAVE_SRC; > binmode STDOUT, ":encoding($Encode::Locale::ENCODING_CONSOLE_OUT)"; > binmode STDERR, ":encoding($Encode::Locale::ENCODING_CONSOLE_OUT)"; > > STDOUT->autoflush(1); > STDERR->autoflush(1); > > #decode @ARGV > Encode::Locale::decode_argv(Encode::FB_CROAK); > } > > use v5.18.1; > use utf8; > use strict; > use warnings ( qw(all), FATAL => qw(utf8), NONFATAL => qw() ); > no if $] >= 5.018, warnings => qw(experimental); > use feature qw(:all); > use mro qw(c3); > use autodie qw(:all); > use threads ( exit => 'threads_only' ); > use threads::shared; > > use namespace::sweep(); > use Devel::Hook(); > use B::Hooks::EndOfScope::XS(); > use Hook::AfterRuntime(); > > sub import { > my ( $class, @import ) = @_; > my @tags = grep { substr( $_, 0, 1 ) ne q{-} } @import; > my $caller = caller; > > utf8->import(); > strict->import(); > warnings->import( 'all', FATAL => qw(utf8), NONFATAL => qw() ); > warnings->unimport(qw(experimental)) if $] >= 5.018; > feature->import( ( version->new($])->normal ) =~ s/^v/:/r ); > mro::set_mro( $caller, 'c3' ); > > P::Core::Config->import(@tags); > P::Core::Constants->import(@tags); > P::Core::Dump->import(@tags); > P::Core::Exceptions->import(@tags); > P::Core::Events->import(@tags); > P::Core::Functions->import(@tags); > P::Core::GO->import(@tags); > P::Core::Log->import(@tags); > P::Core::I18N->import(@tags); > > unless ( '-config' ~~ @_ ) { > unless ( '-no-autoclean' ~~ @_ ) { > namespace::sweep->import( -cleanee => $caller, -also => [] ); > } > > if ( $caller eq 'main' ) { #main namespace > > #install CORE::CLI event caller > unless ( '-no-cli' ~~ @import ) { > Devel::Hook->push_INIT_hook( > sub { > P::throw_event('CORE::CLI'); > } > ); > } > > #install CORE::RUNTIME event caller > Devel::Hook->push_INIT_hook( > sub { > P::throw_event('CORE::RUNTIME'); > } > ); > } > else { #non-main namespace > > #cli for non-main namespace > if ( '-cli' ~~ @import ) { > push @P::Core::CLI::PACKAGES, $caller; > } > > #apply exception and log roles to moose classes > B::Hooks::EndOfScope::on_scope_end { > if ( $caller->can('meta') && $caller->meta->isa('Moose::Meta::Class') ) { > Moose::Util::apply_all_roles( $caller->meta, 'P::Core::Exceptions::Role' ); > Moose::Util::apply_all_roles( $caller->meta, 'P::Core::Log::Role' ); > } > }; > > #make moose classes immutable > unless ( '-no-immutable' ~~ @_ ) { > Hook::AfterRuntime::after_runtime { > if ( $caller->can('meta') && $caller->meta->isa('Moose::Meta::Class') ) { > $caller->meta->make_immutable; > } > }; > } > } > } > > #export autodie pragma > unless ( '-no-autodie' ~~ @import ) { > @_ = ( 'autodie', Fatal::LEXICAL_TAG, ':all' ); > goto &Fatal::import; > } > return; > } > > This package used first in all other our modules. As you can see it imports all needed functionality automatically, install hooks, etc... > > We use Moose and other modules after our core package used. And now Moose override our warning policy. >
Please, add some package variable to Moose or Moose::Exporter namespaces, which can be used to turn off warnings export.
On Sun Nov 24 19:55:21 2013, ZDM wrote: Show quoted text
> Please, add some package variable to Moose or Moose::Exporter > namespaces, which can be used to turn off warnings export.
I doubt we will add a package variable to do this. I think you could work around this by making your own core package for Moose, like P::Moose. We've done this for Moose, Moose::Role, MX::Role::Parameterized, and Test::Class::Moose at my work place, and it gives us full control over when Moose is exported, as well as warnings, strict, autodie, etc. You can also include various MX modules by default, like MooseX::StrictConstructor. Also, BTW, you can use Import::Into to export autodie rather than the goto hack. Just make sure that you pass a numeric caller level to autodie->import::into.
Subject: Re: [rt.cpan.org #90774] Make it possible to disable Moose's export of warnings into Moose-using packages
Date: Thu, 27 Nov 2014 20:48:06 +0200
To: bug-Moose [...] rt.cpan.org
From: "dzagashev [...] gmail.com" <dzagashev [...] gmail.com>
Thanks for the advice. I already have moved on Moo. On 27.11.2014 20:36, Dave Rolsky via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=90774 > > > On Sun Nov 24 19:55:21 2013, ZDM wrote:
>> Please, add some package variable to Moose or Moose::Exporter >> namespaces, which can be used to turn off warnings export.
> I doubt we will add a package variable to do this. > > I think you could work around this by making your own core package for Moose, like P::Moose. We've done this for Moose, Moose::Role, MX::Role::Parameterized, and Test::Class::Moose at my work place, and it gives us full control over when Moose is exported, as well as warnings, strict, autodie, etc. You can also include various MX modules by default, like MooseX::StrictConstructor. > > Also, BTW, you can use Import::Into to export autodie rather than the goto hack. Just make sure that you pass a numeric caller level to autodie->import::into. >