Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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

  • Net::LDAP::Constant parses its own POD to set the constants it provides - key code is roughly
    while (<DATA>) { # get a line of POD if (/^=item\s+(LDAP_\S+)\s+\((.*)\)/) {# look for a POD line of =ite +m LDAP_<constant> (<value>) $const{$name} = sub () { $value }; # set the constant from what wa +s in the POD !!! } }

    Talk about keeping the code and docs in sync - the code IS the doco
  • When running 'make test' for Devel::Cover, it eval's running its own test harness, captures the output, compares it to a set of 'golden' files, which contain its own test output from someone elses machine, for every recent release of perl, to see if your perl works the same as theirs - if so, you pass !!
  • Test::MockObject (my new lust module - use Test::MockObject qw(schwing);)
    The method fake_module() contains the most crystal clear example of populating @INC and the symbol table I have ever seen - just beautiful - key code is roughly
    sub fake_module { my ($class, $modname, %subs) = @_; # replace methods in $modn +ame with those in %subs $INC{ $modname . '.pm' } = 1; # pretend we have already loaded + the module foreach my $sub (keys %subs) { # for each implementation provi +ded ... *{ $module . '::' . $sub } = $subs{ $sub }; # store th +e provided implementation in the symbol table } }

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;


In reply to Interesting WTDI by leriksen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2014-12-22 09:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (113 votes), past polls