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 via Feature::Compat::Class:

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

Optional defer syntax:

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

Optional Object::Pad / Corinna-like syntax:

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

Non-conflicting combinations are allowed:

use Modern::Perl::Prelude qw(
    -utf8
    -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.

This is the forward-compatible class syntax option.

-defer

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

-corinna

Loads and imports Object::Pad into the caller scope.

This is intended for projects that explicitly want Object::Pad / Corinna-like class syntax. It is distinct from -class and may differ semantically from Feature::Compat::Class and future core class behavior.

-class and -corinna are mutually exclusive.

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 via Feature::Compat::Class

  • -defer enables defer

  • -corinna enables class syntax via Object::Pad

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, Object::Pad, 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.

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.