Dynamicly Adding a Method to a Module

We can follow the following steps to add/change a method in a module dynamicly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use strict;
use warnings;
use utf8;
{

    package Data::Dumper;

    sub test {
        print "test to add a new method to Data::Dumper\n";
    }
}

use Data::Dumper;
Data::Dumper::test;
print Dumper \%Data::Dumper::

we can also use the following one liner to check the methods defined in a module:

1
perl -e "use File::Find; use Data::Dumper; print Dumper \%File::Find::"

or we can use JSON to print out its format:

1
perl -e "use File::Find; use JSON; print to_json(\%File::Find::)"