Loading…
Back To Schedule
Tuesday, June 8 • 12:00 - 12:50
perlimports or "Where did that symbol come from?"

Sign up or log in to save this to your schedule, view media, leave feedback and see who's attending!

Feedback form is now closed.
Download slides: curl https://raw.githubusercontent.com/oalders/presentations/main/slides/6-perlimports/remark.html -o perlimports.html && open perlimports.html

---

Perl import statements (like "use POSIX;") allow you to import symbols into your package, but they also allow lots of other shenanigans to take place. We'll explore avoiding pitfalls when importing modules, implementing best practices when importing and how to automate this via App::perlimports.

This talk will be made up of several parts.

How imports work

This will include a discussion of Exporter, Sub::Exporter and Import::Into. It will probably include some examples of other unexpected behaviour that may take place when Foo->import is called.

We will discuss why knowing what every CPAN module exports is almost impossible, but we'll review some techniques which we can use to maximize the number of modules we can reliably inspect for exports. There will be a brief discussion on how Import::Into can be used to create your own pragmas, or even your own flavour of Moose.

Why imports can introduce a maintenance burden on new and even experienced Perl programmers

Unmanaged import statements allow many unused symbols to be imported into existing code. Bare import statements and even import tags make it hard to discover where functions and other symbols originate from. Managing existing import statements gives us a chance to make code more readable, clarify the origin of imported symbols, remove unused dependencies and even speed up code compilation.

There will be a brief discussion of existing Perl::Critic policies which try to address this. We will look at using dump-perl-exports as a tool to discover what a module really exports.

App::perlimports

Bare imports and import tags provide the code author with a convenience, but this can come at the cost of readability for everyone else. We will walk through using perlimports from the command line and see how it attempts to clean up import statements in a selection of a code, a file or even an entire codebase. We will discuss how to use similar techniques with a simple vim integration, so that imports can be cleaned up directly in the vim editor. If perlimports does not present itself as a workable solution for an audience member, the preceding discussion should provide some food for thought as to how technical debt on an existing code base can be reduced through wise use of import statements.

Speakers
avatar for Olaf Alders

Olaf Alders

Senior Software Engineer, MaxMind Inc
I am coder #1 on MetaCPAN. I help keep a bunch of Perl modules mostly up to date. In my spare time I occasionally pick up a guitar and stand behind a microphone. I am into running, cycling and open water swimming. My kids are teaching me how to skateboard.


Tuesday June 8, 2021 12:00 - 12:50 EDT
Zoom Room 1
  Track 1