http://www.perlmonks.org?node_id=11116822


in reply to Exporting use strict/warnings into main::

Perhaps Import::Into?

  • Comment on Re: Exporting use strict/warnings into main::

Replies are listed 'Best First'.
Re^2: Exporting use strict/warnings into main::
by 1nickt (Abbot) on May 15, 2020 at 17:49 UTC

    Yes ++

    updated: minidb dumper, thx marioroy

    From a bundle I use a lot:

    use strict; use warnings; package My::Bundle { use Data::Dumper::AutoEncode (); use Data::Rmap 'rmap_ref'; use Import::Into; use parent 'Exporter'; our @EXPORT = 'Dumper'; sub import { shift->export_to_level(1); strict ->import::into(1); warnings ->import::into(1); strictures ->import::into(1, 2 => 1); feature ->import::into(1, 'say', 'state'); utf8 ->import::into(1); autodie ->import::into(1); Encode->import::into(1); List::Util->import::into(1, qw/ any all first max maxstr min m +instr sum sum0 pairkeys pairvalues pairgrep pairmap shuffle uniq /); Method::Signatures->import::into(1); Path::Tiny->import::into(1); Time::Piece->import::into(1); Time::Seconds->import::into(1); Try::Tiny->import::into(1); } # These are global vars; localize them unless # you want *everything* to be changed $Data::Dumper::Deepcopy = 1; $Data::Dumper::Indent = 1; $Data::Dumper::Purity = 1; $Data::Dumper::Quotekeys = 0; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Terse = 1; sub Dumper { rmap_ref { if ( my $class = ref($_) ) { $class = $_->blessed if $class eq 'MCE::Shared::Object +'; if ( $class->isa('MCE::Shared::Array') ) { $_ = [ $_->can('export') ? @{ $_->export } : $_->v +alues ]; } elsif ( $class->isa('MCE::Shared::Hash') ) { $_ = { $_->can('export') ? %{ $_->export } : $_->p +airs }; } elsif ( $class->isa('MCE::Shared::Minidb') ) { my $db = $_; $_ = $db->lkeys ? [ { $db->hpairs }, { $db->lpairs + } ] : [ { $db->hpairs } ]; } elsif ( $class->isa('MCE::Shared::Ordhash') ) { $_ = $_->clone; } elsif ( $class->isa('MCE::Shared::Scalar') ) { $_ = $_->get; } } } @_; return Data::Dumper::AutoEncode::eDumper(@_); } }; 1; # return true

    Hope this helps!


    The way forward always starts with a minimal test.

        But I do not want them localized. I want global changes on Data::Dumper output. That's why I wrote it like that.

        Edit: Oh, you are saying it's a dangerous example, I see. I'll update the node.


        The way forward always starts with a minimal test.