Skip to content

Instantly share code, notes, and snippets.

@Ovid
Last active August 11, 2020 01:49
Show Gist options
  • Save Ovid/ad0468734a6f3af9984e68e3a5e79d93 to your computer and use it in GitHub Desktop.
Save Ovid/ad0468734a6f3af9984e68e3a5e79d93 to your computer and use it in GitHub Desktop.
use less boilerplate
package Less::Boilerplate;
use 5.26.0;
use strict;
use warnings;
use feature ();
use utf8::all;
use autodie ();
use Carp;
use Try::Tiny;
use Import::Into;
sub import {
my ($class) = @_;
my $caller = caller;
warnings->import::into($caller);
# sadly, we still often get warnings
warnings->unimport::out_of($caller, 'experimental::signatures');
strict->import::into($caller);
feature->import::into($caller, qw/signatures :5.26/);
utf8::all->import::into($caller);
Try::Tiny->import::into($caller, qw(try catch finally));
Carp->import::into($caller, qw(carp croak));
autodie->import::into($caller, ':all');
}
sub unimport {
my $caller = caller;
warnings->unimport::out_of($caller);
strict->unimport::out_of($caller);
feature->unimport::out_of($caller);
utf8::all->unimport::out_of($caller);
Try::Tiny->unimport::out_of($caller);
autodie->unimport::out_of($caller);
Carp->unimport::out_of($caller);
}
1;
__END__
=head1 NAME
Less::Boilerplate - Use modern Perl features
=head1 SYNOPSIS
use Less::Boilerplate;
=head1 DESCRIPTION
This module is a replacement for the following:
use strict;
use warnings;
use v5.26;
use feature "signatures';
no warnings 'experimental::signatures';
use utf8::all;
use Carp qw(carp croak);
use autodie ':all';
use Try::Tiny;
Due to the nature of experimental features, you usually want to C<use> this
module after you C<use> other modules or else you will still get the warning
about experimental signatures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment