Removing Boilerplate with Import::Into

I recently started a new project and wanted to take advantage of some cool new Perl 5.20 features. In particular, I wanted to use the experimental subroutine signatures feature and postfix dereferencing. That requires the following incantation:

use feature 'signatures';
use feature 'postderef';
no warnings 'experimental::signatures';
no warnings 'experimental::postderef';

That can be abbreviated a bit by passing a list to feature and just turning off the entire experimental class of warnings:

use feature 'signatures', 'postderef';
no warnings 'experimental';

But it's still a couple lines of boilerplate that need to be pasted atop every file in my project. I hate pasting things.

Read more on my blog: Removing Boilerplate with Import::Into


I had the same problem, and I kept repeating the solution, so I wrote a module: Import::Base

I use Import::Into for avoiding boilerplate in my tests:

# t/lib/MyApp/
package MyApp::TestKit;

use strict;
use warnings;
use Import::Into;
use FindBin qw/$Bin/;
use lib "$Bin/../lib";
use MyApp::Util;
use Test::More;
use Test::Warnings;
use Test::Fatal;
use utf8;

# load config file
# instead of

sub import {
my $target = caller;
Test::Warnings->import::into($target, qw/ :all /);
Test::Fatal->import::into($target, qw/ exception /);


# and in each test file.

#!/usr/bin/env perl
use FindBin qw/$Bin/;
use lib "$Bin/lib";
use EPPlication::TestKit;
# test code

hi ether? what do you want to express with your comment? Did Jimmy fall in the well? ;)

@davewood: use experimental qw< signatures postderef >;

Leave a comment

About Mike Friedman

user-pic Mike Friedman is a professional computer programmer living and working in the New York City area.