http://www.perlmonks.org?node_id=406292

There is a wisdom that states "If you want to be a great coder, read great code" - in other words, learn from those who have come before. In perl, this can be done quite easily by rummaging around in the catacombs of the Monastery, or by skulking around inside CPAN.

When you start doing this, I think one of the most striking thing is just how many WTDI (Ways To Do It - from TMTOWTDI) some modules employ. Some of my favourites are

Those are just three recent ones where I suddenly stopped reading, sat up and went 'Thats ... incredible'.

Perhaps other monks would care to share the wonderful ideas (and weird ones too ... ) held in CPAN.

use brain;

Replies are listed 'Best First'.
Re: Interesting WTDI
by nimdokk (Vicar) on Nov 09, 2004 at 12:50 UTC
    Don't have any interesting ways of doing things but I'm definitly going to take a look at the way that POD is handled in the Net::LDAP::Constant that you describe and see if its something I might be able to incorporate into the code library we have here where I work (home-grown module).
      I think Pod::Constants provides another way of extracting constants from the POD.
        I'll keep that in mind, thanks.
Re: Interesting WTDI
by monoxide (Beadle) on Nov 09, 2004 at 22:22 UTC
    Hmmm... I have no jewels of wisdom, but i was just wondering...

    Would it be possible to create/implement your own namespaces by using similar code to the Test::MockObject which is provided above? Kind of like, (guessing here...)
    $INC{"MyModule.pm"} = 1; # "load" module *{"MyModule::TestSub"} = /&TestSub; # "load" a method
    Would that be correct?
      $INC{"MyModule.pm"} = 1; # "load" module *MyModule::TestSub = \&TestSub; # "load" a method

      Jenda
      We'd like to help you learn to help yourself
      Look around you, all you see are sympathetic eyes
      Stroll around the grounds until you feel at home
         -- P. Simon in Mrs. Robinson

      You only need to set a key in %INC if you want to prevent use or require from attempting to load a module from disk. (You could also put a coderef in @INC, but this way is a lot simpler.