2024 twenty-four merry days of Perl Feed

Programming like a BEAST

e - 2024-12-10

Enhance Your Development Workflow with the e Module

You know how certain aspects of development can be a real drag - slow and pretty boring? I’ve definitely been there. But here’s where the e module comes in and changes the game.

Rapid Prototyping

The e module comes loaded in with many features that can aid in rapid prototyping as well as testing.

Let's Make Selenium Testing Less Painful Again

One of its cool features is the repl breakpoint command, which can seriously simplify debugging and testing processes across the board.

It can also be used from the command line like this:

perl -Me -e 'my $var = 111; repl'

With that simple one-liner, you trigger an interactive breakpoint which pauses the execution of the program.

You can investigate data and try things out.

Once satisfied, you can quit the debugger and code flow would continue as usual.

So, instead of dealing with all the usual hassle of setting "breakpoints" and debugging manually (yes, I taking about you print), you can use e to just pop in a breakpoint whenever you need it. This means you can pause execution, check out what’s going on, and make adjustments on the fly.

A prime example of where e shines is in Selenium testing, where it can significantly ease the process. Selenium tests can be notoriously slow and cumbersome, but the repl breakpoint feature makes it less painful.

However, it’s not just for Selenium, e can enhance various development tasks by making the whole debugging and testing experience accelerated, quickly done, and, dare I say, even a bit enjoyable.

More Tricks up its Sleeve

Besides making a fancy breakpoint, e can a wide array of tricks to help one in common daily tasks.

The Obnoxious Say

Have you ever added a print statement, only to realize that there is no output for some reason? (Assuming you have no syntax errors).

Now, imagine working in a large, complex codebase where, buried deep within a function, STDOUT or STDERR is being closed.

close STDOUT;
open STDOUT, '>', '/dev/null';

say "You wont ever see this :(";

So you now need to find the place that closes STDOUT to comment it out for debugging or figure out how to print it to the screen (maybe there is a --verbose option).

Say Hello to the Obnoxious Say

use e;

print "You'll see this.\n.";
say "And this";

close *STDOUT;
close *STDERR;

print "But not this.\n";
say "YOU'll STILL SEE THIS!";

Whether your output streams are open, closed, or redirected, the obnoxious say will always ensure the message gets displayed on your screen.

Pod Table Of Contents

Need a quick overview of a Perl module? Well, the pod command-line tool (included with e is your friend.

Using it you can get a quick overview of a module:

- Methods names and summaries. - Module inheritance. - Jump into the module quickly (via Vim).

At a glance I can see what methods are available for a module.

For Mojo::UserAgent

For Mojo::JSON

Can also look at a specific method:

Using the edit option you can also jump inside the module file to explore how it works:

(In that case above, need to press n again to find the actual definition of the method)

Performance Efficiency

Worried about performance? Well, stop it! e has been optimized to have a very tiny footprint to conserve space and resources. Also, it makes great use of Just In Time (JIT) module loading: you pay only for what you use. For instance, I use it on my smartphone with Termux, and it’s incredibly fast - even with the phone's limited resources. The impact is practically negligible, and it runs smoothly without any noticeable delays.

Interactive Demos

To see e in action, just install it with cpan(m):

cpanm e

Then skim through the short doc.

You can also try out this Perl Banjo interactive demo. You can run a few example snippets and experiment with them directly.

Feel free to modify the snippets on the right to explore different features and see how e can enhance your own development workflow.

(Unfortunately, at this time, not all features can be currently used in PerlBanjo.)

Your Turn

With the power of e at your fingertips, it’s time to dive in and explore! Whether you’re easing the pain of Selenium testing, ensuring your output is always present with the obnoxious say, or seamlessly navigating documentation using pod, e is here to transform your experience. Try it out and see how it fits into your workflow!

Gravatar Image This article contributed by: tim.potapov+advent@gmail.com