NAME

Modern::Perl::Prelude - Project prelude for modern Perl style on Perl 5.30+

SYNOPSIS

use Modern::Perl::Prelude;

state $counter = 0;
my $s = trim("  hello  ");

try {
    die "boom\n";
}
catch ($e) {
    warn $e;
}

Optional UTF-8 source mode:

use Modern::Perl::Prelude '-utf8';

Optional class syntax:

use Modern::Perl::Prelude '-class';

Optional defer syntax:

use Modern::Perl::Prelude '-defer';

Any combination is allowed:

use Modern::Perl::Prelude qw(
    -utf8
    -class
    -defer
);

Disable native pragmata/features lexically again:

no Modern::Perl::Prelude;

DESCRIPTION

This module bundles a small, opinionated set of pragmata, features, and compatibility layers for writing Perl in a Perl 5.40+-style while staying runnable on Perl 5.30+.

It enables:

  • strict

  • warnings

  • feature say, state, fc

  • Feature::Compat::Try

  • selected functions from builtin::compat

Additional compatibility layers may be requested explicitly via import options.

IMPORT OPTIONS

-utf8

Also enables source-level UTF-8, like:

use utf8;

-class

Loads and imports Feature::Compat::Class into the caller scope.

-defer

Loads and imports Feature::Compat::Defer into the caller scope.

DEFAULT IMPORTS

This module always makes the following available in the caller's lexical scope:

say
state
fc
try / catch
blessed
refaddr
reftype
trim
ceil
floor
true
false
weaken
unweaken
is_weak

OPTIONAL IMPORTS

When requested explicitly, this module can also make the following available:

  • -class enables class, method, field, ADJUST

  • -defer enables defer

UNIMPORT

no Modern::Perl::Prelude reliably disables native pragmata/features managed by this module:

strict
warnings
say
state
fc
utf8

Compatibility layers such as Feature::Compat::Try, Feature::Compat::Class, Feature::Compat::Defer, and builtin::compat are treated as import-only for cross-version use on Perl 5.30+ and are not guaranteed to be symmetrically undone by no Modern::Perl::Prelude.

DESIGN NOTES

This is a lexical prelude module. It is implemented via Import::Into so that pragmata and lexical functions affect the caller's scope, not the scope of this wrapper module itself.

Optional compatibility layers are loaded lazily, only when explicitly requested by import options.

AUTHOR

Sergey Kovalev <skov@cpan.org>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.