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

  • Home
  • SEARCH
  • 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 6064217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:15:22+00:00 2026-05-23T09:15:22+00:00

I want make a module for my own default use, e.g.: use My::perldefs; with

  • 0

I want make a module for my own “default use”, e.g.:

use My::perldefs;

with the following content (mostly based on tchrist’s post.)

use 5.014;
use strict;
use features qw(switch say state);

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 qw(:std :utf8);
use charnames qw(:full);
use feature qw(unicode_strings);
use Encode qw(encode decode);
use Unicode::Normalize qw(NFD NFC);
use Carp qw(carp croak confess cluck);
use autodie;

Simply, want achieve one use My::perldefs for achieving

  • full and correct utf8 support, and with
  • all modern perl features turned on.

Based on recent question the good start-point is uni::perl. It is do nearly all things what I want, only need add:

use feature qw(unicode_strings);
use charnames qw(:full);
use Encode qw(encode decode);
use Unicode::Normalize qw(NFD NFC);
use autodie;

I will award with the bounty someone who will extend the uni::perl (inseretd bellow) with the above 5 lines, using an effective and correct way.

Please, HELP make an good boilerplate for utf8 and modern perl use. Thanks.


Bellow is the copy of uni::perl.

package My::perldefs;

use 5.014;
BEGIN {
    ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
    $^H |= 0x00000602;
}
m{
use strict;
use warnings;
}x;
use mro ();

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

sub import {
    my $me = shift;
    my $caller = caller;
    ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";

    $^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");

    for my $sub (qw(carp croak confess)) {
        no strict 'refs';
        *{ $caller .'::'. $sub } = \&$sub;
    }
    while (@_) {
        my $feature = shift;
        if ($feature =~ s/^://) {
            my $package = $me. '::'. $feature;
            eval "require $package; 1" or croak( "$@" );
            $package->load( $caller );
        }
    }
}

1;

Ps:

All of the above is (C): Mons Anderson, C<< <mons at cpan.org> >>
  • 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-23T09:15:23+00:00Added an answer on May 23, 2026 at 9:15 am

    use feature qw(unicode_strings) is easy, $^H{feature_unicode} simply needs to be set. The other modules aren’t too hard as well, one simply needs to use require and call the necessary module functions explicitly (e.g. Encode and Unicode::Normalize define an export method via Exporter that takes the calling package as a parameter). The tricky one is autodie, it really goes strictly by the value of caller and will normally inject its functions into My::perldefs package. I think the only good solution here (short of reimplementing the module in My::perldefs) is using goto – this allows calling the required method without changing caller, so the methods are injected into the correct namespace. Here is what I got in the end:

    package My::perldefs;
    
    use 5.014;
    BEGIN {
        ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
        $^H |= 0x00000602;
    }
    m{
    use strict;
    use warnings;
    }x;
    use mro ();
    
    BEGIN {
        for my $sub (qw(carp croak confess)) {
            no strict 'refs';
            *$sub = sub {
                my $caller = caller;
                local *__ANON__ = $caller .'::'. $sub;
                require Carp;
                *{ $caller.'::'.$sub } = \&{ 'Carp::'.$sub };
                goto &{ 'Carp::'.$sub };
            };
        }
    }
    
    sub import {
        my $me = shift;
        my $caller = caller;
        ${^WARNING_BITS} ^= ${^WARNING_BITS} ^ "\xfc\x3f\xf3\x00\x0f\xf3\xcf\xc0\xf3\xfc\x33\x03";
    
        $^H |=
              0x00000602 # strict
            | 0x00800000 # utf8
        ;
    
        # use feature
        $^H{feature_switch} =
        $^H{feature_say}    =
        $^H{feature_state}  =
        $^H{feature_unicode}= 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");
    
        #use charnames qw(:full)
        require charnames;
        charnames->import(":full");
    
        #use Encode qw(encode decode)
        require Encode;
        Encode->export($caller, "encode", "decode");
    
        #use Unicode::Normalize qw(NFC NFD)
        require Unicode::Normalize;
        Unicode::Normalize->export($caller, "NFC", "NFD");
    
        for my $sub (qw(carp croak confess)) {
            no strict 'refs';
            *{ $caller .'::'. $sub } = \&$sub;
        }
        while (@_) {
            my $feature = shift;
            if ($feature =~ s/^://) {
                my $package = $me. '::'. $feature;
                eval "require $package; 1" or croak( "$@" );
                $package->load( $caller );
            }
        }
    
        #use autodie qw(:default)
        #goto needs to be used here to make sure that caller doesn't change
        require autodie;
        @_ = ("autodie", ":default");
        goto &autodie::import;
    }
    
    1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I frequently use Moose to make sure my data have suitable default values, like
I want to make my table rates volumetric, i.e. the weight based on width,
For example I want to add my own has_many_stuff in ActiveRecords. So I make
I want make datetimepicker in my project. Using jquery how it is possible? I
Let's say I want make some of my sources publicly available via my blog
I have style sheet with a class name changebackgroundcolor i want make change in
I am traversing a HTML document using javascript DOM. I want make a list
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I want to make a copy of an ActiveRecord object, changing a single field

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.