Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:49+00:00 2026-05-23T10:25:49+00:00

In my pervious question I asked how to use multiple modules with one use.

  • 0

In my pervious question I asked how to use multiple modules with one use. Got one perfect answer, and another one what pointed me to Modern::Perl module what is really simple.

After a bit searching CPAN I found another module called uni::perl, what is really complicated – it is and equivalent for:

use strict;
use feature qw(say state switch);
no warnings;
use warnings qw(FATAL closed threads internal debugging pack substr malloc
                unopened portable prototype inplace io pipe unpack regexp
                deprecated exiting glob digit printf utf8 layer
                reserved parenthesis taint closure semicolon);
no warnings qw(exec newline);
use utf8;
use open (:utf8 :std);
use mro 'c3';

Can someone explain/comment it how its works?

I pasted the whole code here divided into few segments and added my questions into, (with ###).

I understand than this question is really long. But, dividing it into smaller one will not help, because the whole is about the “uni::perl” module.

Please, help me understand the problematic parts.


package uni::perl;
use 5.010;
BEGIN {
    ### OK - these are bitmask of different warnings, they're coming from:
    # paste this into perl to find bitmask 
    # no warnings;
    # use warnings qw(FATAL closed threads internal debugging pack substr malloc unopened portable prototype
    #                 inplace io pipe unpack regexp deprecated exiting glob digit printf
    #                 utf8 layer reserved parenthesis taint closure semicolon);
    # no warnings qw(exec newline);
    # BEGIN { warn join "", map "\\x$_", unpack "(H2)*", ${^WARNING_BITS}; exit 0 };

    ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
    $^H |= 0x00000602; ### this mean "use strict;"
}

Setting directly the ${^WARNING_BITS} an the $^H, is faster than a common “use strict” and etc?


What doing this m{ }x.

m{
use strict;
use warnings;
}x;
use mro ();

I know the “match” operator and ‘x’ flag but not understand what is doing in this context.. use mro is some “dark-magic” what probably an common perl users don’t need to know… 😉


What’s do the local *__ANON__ line? For what is good the goto in this context?
The whole next BEGIN block is an dark magic for me. ;(

BEGIN {
    for my $sub (qw(carp croak confess)) {
        no strict 'refs';
        *$sub = sub {    ### for what need replace the global *croak (etc) with this sub?
            my $caller = caller;
            local *__ANON__ = $caller .'::'. $sub;  ### what's mean this?
            require Carp;

                    ### This set the Carp code-refs to the global namespace?
                    ### But who is the "caller" in the BEGIN block? (compile time)

            *{ $caller.'::'.$sub } = \&{ 'Carp::'.$sub };

            goto &{ 'Carp::'.$sub }; ### Why need goto here?
        };
    }
}

Finally – some clearer things. Rewrite the import so, this will be called when use uni::perl;

sub import {
    my $me = shift;
    my $caller = caller;

    ### OK - again the bitmasks
    ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";


    ### where are these documented?
    $^H |=
          0x00000602 # strict
        | 0x00800000 # utf8
    ;

    # use feature
    $^H{feature_switch} =
    $^H{feature_say}    =
    $^H{feature_state}  = 1;

    # use mro 'c3';
    mro::set_mro($caller, 'c3');

    #use open (:utf8 :std);
    ${^OPEN} = ":utf8\0:utf8";
    binmode(STDIN,   ":utf8");
    binmode(STDOUT,  ":utf8");
    binmode(STDERR,  ":utf8");


    ### again coderef magic. As I understand it - it will replace the
    ### "carp, etc" in the callers namespace with the coderef's defined
    ### in the above BEGIN block. But why with this complicated way?

    for my $sub (qw(carp croak confess)) {
        no strict 'refs';
        *{ $caller .'::'. $sub } = \&$sub;
    }

    ### and finally - I have abosolutely no idea - what do the next code
    ### will take arguments of "use uni::perl qw(arg)"
    ### but have no idea how to use it - or what is doing ;(
    while (@_) {
        my $feature = shift;
        if ($feature =~ s/^://) {
            my $package = $me. '::'. $feature;
            eval "require $package; 1" or croak( "$@" );
            $package->load( $caller );
        }
    }
}

what is doing the last while?

Plus question:

  • why do the same things twice? Once in BEGIN block and once in import? (import is for the “use” – but why doing nearly the same thing in the “BEGIN” block too?

Because this question has more parts, please, quote the relevant part when you giving an answer.

THANK YOU ALL IN ADVANCE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:25:49+00:00Added an answer on May 23, 2026 at 10:25 am
    1. Setting the warning bits directly is a bit faster, and has more predictable behavior (you can see everything that should happen), but it is obviously much harder to work with and maintain. It may be that the set of warnings that uni::perl is trying to load is easier done through the bitmasks.

    2. m{ use strict; use warnings;}x; is simply a regex in void context. It would throw an error either about context or $_ not being set if warnings were enabled. I am not sure exactly why this is being done, it might be to appease some code metric system that looks for the lines “use warnings; use strict”. I would have probably written it q{...} if 0; which is at least a little clearer.

    3. This BEGIN block is creating custom versions of the functions in Carp. It is using the local *__ANON__ = ... line to set the name of any anonymous subroutines so that the Carp stack trace is easier to follow. The BEGIN block creates the wrapped Carp routines. The import subroutine then loads these new wrapped routines into the caller’s namespace.

    4. That last while seems to be loading additional plugin modules for uni::perl.

    5. The same thing is not being done, see the answer to #3. (BEGIN creates the wrapped routines, import installs them into the caller’s space)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a previous question I asked, the suggested answer was for me to partition
This question is being asked because of this one . C++11 allows you to
Following on from a previous question in which I asked: How can I use
Relating to another question I asked yesterday with regards to logging I was introduced
Well in a previous question I asked the same thing, but the answer that
I've asked a question like this before but this one is different, this is
I asked a question similar to this one a couple of weeks ago, but
So in a previous question I asked about implementing a generic interface with a
In a previous question I asked about how to group XML elements logically, and
this question is an extension to a previous question i asked (and was answered).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.