LOGO

                      ⢀⣀⡤ ⢀⣤⣿⡗ ⣀⣀⣀
          ⢀⣤⣤⣤⣄⡀    ⣠⡶⠿⠛⣹⡾⠛⢁⡼⠟⢛⠉⠉⠉⣉⣣⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡄
      ⢉⠻⣯⣉⡛⠒⠻⡷⢮⡙⠳⣤⡐⣾⠟⣀⣴⠋⠁⣀⡴⠋ ⣠⡟ ⠐⠚⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢩⠛
      ⠘⣧ ⠹⣿⡳⡀⠙⢦⡈⠳⠈⢱⡟ ⠋⣼⣿⣿⢿⠁⠰⣶⠏⢐⡆⢠  ⣠⣖⣢⠤⠶⠶⠂ ⡽⢃  ⣀
       ⠈⢗⣲⠞⠓⠛⢦⡌⡿  ⡾⠃  ⣿⣿⡾   ⣿ ⣼⣠⠏⢀⡾⣿⠟⣂⣠⡤⠤⠴⠶⠛⠛⠛⢋⡿
   ⢀⡴⡲⠹⠍⠁ ⠐⢶⡂⠈⣓⠱⣆⡼⠃  ⢰⣿⡟⢳ ⢀⣾⢇⡜⠋⠁⣰⣯⠾⠷⠚⠉ ⢀⣴⠎    ⢸⡇
   ⠘⠙⠳⠤⣕ ⠳⣄ ⠉⠓⢴⣱⣿⡅⣀⣤⠾⣟⣯⣤⣶⡶⢿⣿⣯⠆ ⢈⣽⠃⣀⣀⣠⣴⣾⣯⠄     ⣴⠇
      ⢀⣹⣶⡀⢈⣷⣶⣤⣼⣿⡿⢗⡋⣩⣶⡟⣛⣿⣿⣷⣾⣛⣉⣀⡤⠾⠛⠒⠋⠉⠛⣿⡿⠋     ⢠⡏
     ⠙⠛⣲⡶⣤⣤⣿⡿⠋⠁⠻⠿⠛⠛⠙⠛⠛⠋⠉⠹⠿⠿⢿⣿⣏⣠⡖⣀⢀⣠⠤⢀⣈⣳⣄     ⢨⣶⣦⡤⣄⣀
      ⠉⢁⣴⣋⣸⠟       ⣰⣶⠴⠒      ⠈⠛⠻⢿⣿⣿⡛⠋⠉⠙⣿   ⣠⡶⣫⣭⠶⣭⡀
     ⢀⣴⠟⠉⢡⡏⡼   ⢠⡞  ⠉            ⢸⣿⡿⢿⡒⠒⠲⠿⠶⠶⠶⠟⠋⠁⣀⣀⣀⠉⠳⣄
    ⠲⣿⠷⠃⢀⣾⠷⠿⠦⢤⣤⡟   ⢀⣀⣤⣶⣯⣥⣤⣤⡞⠁   ⠈⣼⣿⣷⣝⡳⠤⣤⣀⣀   ⠉  ⠙⠻⢦⣈⢳⡄
   ⢀⡼⢋⣤⠴⠋⠁   ⣴⠿⠿⢶⣶⣿⣿⠟⠛⢻⣿⣿⠟⠁      ⠈⠻⣿⡍⠛⠷⣦⣄⡀⠳⢤⡀      ⠙⠧⣄
  ⣠⣿⠟⠉    ⣀⣀⡀ ⣤⣤⣼⣿⣿⣷⣂⣴⣿⡿⠋      ⠰⡆ ⢻⣿⣿⣶⣄⡈⠻⣝ ⠈⠙⠲⣤⣀⡀  ⠑⢦⣌⡙⠒
 ⢰⡟⠁     ⠛⢩⠶⠖⠛⣀⡏⠉⠙⠿⣿⣿⡟⠉         ⣷  ⣿⣿⣧⡙⢷⣄⡈⠂     ⠉⠉⠙⢷⡄⠈⠛⢦
⣠⡿⠛⢶⣦⣤⣤⣴⣶ ⠈⡿⠟⠛⠉⠁⢀⣀⣀ ⠉⠙⠛⠒⠂       ⡿ ⣽⣿⠘⢻⣷⡀⠈⠉⠉         ⠹⣆  ⠁
⡏  ⢸⣿⡿⠉⠙⠋ ⠈      ⠈⠉⣉⠅ ⠓⠲⢤⣄⡀    ⣼⠃ ⢿⣿  ⣿⠇⢠⡀       ⠠⣄⣄ ⢹⡆
⣷⡀  ⡿       ⣀⠔   ⣠⣞⣁⣀⣠⣤⣤⣷⣌⠙⢦⡀⢀⡾⠃  ⢸⣿⡆⣻⠇  ⢹⣄       ⢹⡌⢳⣜⡟
⢻⣧⣠⣸⡇          ⣠⡾⠟⠛⠉⣥⡾⢿⣿⣿⣿⣆ ⠙⠃    ⣿⢏⣿⡿⡀   ⠻⣷⢤⡀    ⢸⡇ ⢿⡇
 ⠉⢻⢿⣿⣶⣤⣤⣀⣀⣀⣀⣤⣴⡿⠋⠁⣠⡴⠟⢁⣴⣿⣿⣿⣿⣿⡆     ⣼⡟⣼⣿⣷⢻⡜⣆  ⠘⢷⡙  ⣠⣤⡿ ⠈⠛⠁
  ⠘⠦⢿⣍⠉⠉⠉⠙⢿⠩⢻⣿⣾⠞⠛⠁  ⣾⠏⠈⢻⣿⣿⣿⣿⡀⡀   ⢻⣰⠟⠁⠘⢦⡻⣿⡆  ⢸⣷  ⣿⡟⠁
     ⠙⠋⠛⠳⣶⣶⠷⢾⣿⣿    ⢀⣿   ⢻⣿⣿⣿⡧   ⢀⣴⠋    ⠁⠈⢳  ⣸⠙⣦⢰⡟
         ⠘⣿⣄⢼⣿⣿⣇⠒⢢⣿⣼⣧⡀ ⢤⡀⣿⣿⣿⡧  ⢀⣾⠃  ⢀⢠⡆  ⡞⢀⡴⣃⣸⡟⠳⣇
          ⠹⡽⣾⣿⠹⣿⣆⣾⢯⣿⣿ ⡞ ⠻⣿⣿⣿⠁ ⢠⣿⢏  ⡀ ⡟  ⢀⣴⣿⠃⢁⡼⠁ ⠈
            ⠈⠛ ⢻⣿⣧⢸⢟⠶⢾⡇  ⣸⡿⠁ ⢠⣾⡟⢼  ⣷ ⡇ ⣰⠋⠙⠁
               ⠈⣿⣻⣾⣦⣇⢸⣇⣀⣶⡿⠁⣀⣀⣾⢿⡇⢸  ⣟⡦⣧⣶⠏ unleashed
                ⠸⢿⡍⠛⠻⠿⠿⠿⠋⣠⡾⢋⣾⣏⣸⣷⡸⣇⢰⠟⠛⠻⡄  v1.26
                  ⢻⡄   ⠐⠚⠋⣠⡾⣧⣿⠁⠙⢳⣽⡟
                  ⠈⠳⢦⣤⣤⣀⣤⡶⠛ ⠈⢿⡆  ⢿⡇
                        ⠈    ⠈⠓  ⠈

NAME

e - beast mode unleashed

SYNOPSIS

Add a trace marker:

$ perl -Me -e 'sub f1 { trace } sub f2 { f1 } f2'

Watch a reference for changes:

$ perl -Me -e 'my $v = {}; sub f1 { watch( $v ) } sub f2 { f1; $v->{a} = 1 } f2'

$ perl -Me -e '
    package A {
        use e;
        my %h = ( aaa => 111 );

        watch(\%h);

        sub f1 {
            $h{b} = 1;
        }

        sub f2 {
            f1();
            delete $h{aaa};
        }
    }

    A::f2();
'

Benchmark two snippets of code:

$ perl -Me -e 'n { slow => sub{ ... }, fast => sub{ ... }}, 10000'

Launch the Runtime::Debugger:

$ perl -Me -e 'repl'

Invoke the Tiny::Prof:

$ perl -Me -e 'prof'

Convert a data structure to json:

$ perl -Me -e 'say j { a => [ 1..3] }'

Convert a data structure to yaml:

$ perl -Me -e 'say yml { a => [ 1..3] }'

Pretty print a data structure:

$ perl -Me -e 'p { a => [ 1..3] }'

Data dump a data structure:

$ perl -Me -e 'd { a => [ 1..3] }'

Devel::Peek dump a data structure:

$ perl -Me -e 'dd { a => [ 1..3] }'

Print data as a table:

$ perl -Me -e 'table( [qw(key value)], [qw(red 111)], [qw(blue 222)] )'
+------+-------+
| key  | value |
+------+-------+
| red  | 111   |
| blue | 222   |
+------+-------+

Encode/decode UTF-8:

$ perl -Me -e 'printf "%#X\n", ord for split //, enc "\x{5D0}"'
0XD7
0X90

$ perl -C -Me -e 'say dec "\xD7\x90"'
$ perl -Me -e 'utf8; say dec "\xD7\x90"'
א

DESCRIPTION

This module imports many features that make one-liners and script debugging much faster.

It has been optimized for performance to not import all features right away: thereby making its startup cost quite low.

SUBROUTINES

Investigation

repl

Add a breakpoint to code.

Basically inserts a Read Evaluate Print Loop.

Enable to analyze code in the process.

CODE ...

# Breakpoint
repl

CODE ...

Simple debugger on the command line:

$ perl -Me -e 'repl'

trace

Show a stack trace.

trace( $depth=1 )

watch

Watch a reference for changes.

watch( $ref, OPTIONS )

OPTIONS:

-clone => 0,               # Will not watch cloned objects.

-methods => "fetch",       # Monitor just this method.
-methods => [ "fetch" ],   # Same.

-levels  => NUM,           # How many scope levels to show.
NUM,                       # Same.

-raw => 1,                 # Include internal calls.
-NUM,                      # Same.

-message => STR,           # Message to display.
STR,                       # Same.

prof

Profile the code from this point on.

my $obj = prof;
...
# $obj goes out of scope and builds results.

n

Benchmark and compare different pieces of code.

Time single block of code.
n sub{ ... };
n sub{ ... }, 100000;

# Compare blocks of code.
n {
    slow => sub{ ... },
    fast => sub{ ... },
};
n {
    slow => sub{ ... },
    fast => sub{ ... },
}, 10000;

Format Conversions

j

JSON Parser.

my $bytes = j([1, 2, 3]);
my $bytes = j({foo => 'bar'});
my $value = j($bytes);

Encode Perl data structure or decode JSON with "j" in Mojo::JSON.

Convert Perl object to JSON string:

$ perl -Me -e 'say j { a => [1..3]}'

Convert JSON string to Perl object:

$ perl -Me -e 'p j q({"a":[1,2,3]})'

x

XML parser.

my $dom = x('<div>Hello!</div>');

Turn HTML/XML input into Mojo::DOM object.

$ perl -Me -e 'say x("<div>hey</dev>")->at("div")->text'

yml

YAML parser.

Convert Perl object to YAML string:

$ perl -Me -e 'say yml { a => [1..3]}'

Convert YAML string to Perl object:

$ perl -Me -e 'p yml "---\na:\n- 1\n- 2\n- 3"'

enc

Encode UTF-8 code point to a byte stream:

$ perl -Me -e 'printf "%#X\n", ord for split //, enc "\x{5D0}"'
0XD7
0X90

dec

Decode a byte steam to UTF-8 code point:

$ perl -C -Me -e 'say dec "\xD7\x90"'
א

utf8

Set STDOUT and STDERR as UTF-8 encoded.

If given a filehandle, will set the encoding for it to UTF-8.

utf8($fh);

Enhanced Types

b

Work with strings.

my $stream = b('lalala');

Turn string into a Mojo::ByteStream object.

$ perl -Me -e 'b(g("mojolicious.org")->body)->html_unescape->say'

c

Work with arrays.

my $collection = c(1, 2, 3);

Turn list into a Mojo::Collection object.

set

Work with sets.

my $set = set(2,4,6,4);

Turn list into a Set::Scalar object.

$ perl -Me -e 'say set(2,4,6,2)'
(2 4 6)

Get elements:

$ perl -Me -e 'say for sort(set(2,4,6,2)->elements)'
$ perl -Me -e 'say for sort(set(2,4,6,2)->@*)'
2
4
6

Intersection:

$ perl -Ilib/ -Me -e 'say set(2,4,6,2) * set(3,4,5,6)'
(4 6)

Create a new universe:

# Universe 1:
# ...
Set::Scalar::Universe->new->enter;
# Universe 2:
# ...

Operations:

set                         value

$a                          (a b c d e _ _ _ _)
$b                          (_ _ c d e f g _ _)
$c                          (_ _ _ _ e f g h i)

union:        $a + $b       (a b c d e f g _ _)
union:        $a + $b + $c  (a b c d e f g h i)
intersection: $a * $b       (_ _ c d e _ _ _ _)
intersection: $a * $b * $c  (_ _ _ _ e _ _ _ _)
difference:   $a - $b       (a b _ _ _ _ _ _ _)
difference:   $a - $b - $c  (a b _ _ _ _ _ _ _)
unique:       $a % $b       (a b _ _ _ f g _ _)
symm_diff:    $a / $b       (a b _ _ _ f g _ _)
complement:   -$a           (_ _ c d e f g h i)

Files Convenience

f

Work with files.

my $path = f('/home/sri/foo.txt');

Turn string into a Mojo::File object.

$ perl -Me -e 'say r j f("hello.json")->slurp'

Output

say

Print with newline.

$ perl -Me -e 'say 123'
$ perl -Me -e 'say for 1..3'

Always sends output to the terminal even when STDOUT and/or STDERR are redirected:

$ perl -Me -e '
    say "Shown before";
    close *STDOUT;
    close *STDERR;
    say "Shown with no stdout/err";
    print "Print not seen\n";
'
111
222

p

Pretty data printer.

$ perl -Me -e 'p [1..3]'

np

Return pretty printer data.

$ perl -Me -e 'my $v = np [1..3]; say "got: $v"'

Can be used with say to output to the terminal (incase STDOUT/STDERR are redirected):

$ perl -Me -e '
    close *STDOUT;
    close *STDERR;
    say np [ 1.. 3 ];
'

d

Data dumper.

$ perl -Me -e 'd [1..3]'

dd

Internal data dumper.

$ perl -Me -e 'dd [1..3]'

dye

Color a string.

$ perl -Me -e 'say dye 123, "RED"'

table

Print data as a table:

$ perl -Me -e 'table( [qw(key value)], [qw(red 111)], [qw(blue 222)] )'
+------+-------+
| key  | value |
+------+-------+
| red  | 111   |
| blue | 222   |
+------+-------+

Context sensitive!

- Void   - output table.
- List   - return individual lines.
- Scalar - return entire table as a string.

g

my $res = g('example.com');
my $res = g('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = g('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = g('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});

Perform GET request with "get" in Mojo::UserAgent and return resulting Mojo::Message::Response object.

$ perl -Me -e 'say g("mojolicious.org")->dom("h1")->map("text")->join("\n")'

l

Work with URLs.

my $url = l('https://mojolicious.org');

Turn a string into a Mojo::URL object.

$ perl -Me -e 'say l("/perldoc")->to_abs(l("https://mojolicious.org"))'

Package Tools

monkey_patch

Insert subroutines into the symbol table.

Extracted from Mojo::Util for performance.

Import methods into another package (as done in this module):

$ perl -e '
    package A;
    use e;
    sub import {
        my $c = caller();
        monkey_patch
            $c,
            new => sub { say "Im new" };
    }
    package main;
    A->import;
    new();
'
Im new

Import methods into the same package (probably not so useful):

$ perl -e '
    package A;
    use e;
    sub import {
        my $c = caller();
        monkey_patch
            $c,
            new => sub { say "Im new" };
    }
    A->import;
    A->new();
'
Im new

Perhaps can be updated based on the outcome of this issue: https://github.com/mojolicious/mojo/pull/2173

pod

Work with perl pod.

import

[Internal] Imports the DSL into another package.

Can be used in a sub class to import this class plus its own commands like this:

package e2;
use parent qw( e );

sub import {
    my ( $class ) = @_;
    my $class = caller;
    $class->SUPER::import( $caller );
    $class->can("monkey_patch")->(
        $caller,
        my_command_1 => sub {},
        my_command_2 => sub {},
        my_command_3 => sub {},
    );
}

AUTHOR

Tim Potapov, <tim.potapov[AT]gmail.com>

BUGS

Please report any bugs or feature requests to https://github.com/poti1/e/issues.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc e

You can also look for information at:

https://metacpan.org/pod/e

https://github.com/poti1/e

Logo was generated using: https://emojicombos.com/dot-art-editor

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by Tim Potapov.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)