About Kent Cowgill
Articles filed under...
abs ab_ripper andylester arms back baggyshorts bestpractices bike blog bugs bus calculator cardio catalyst cgi chart chest chinups code cpan datamodel dbi doctor documentation exercise exhaustion fitness flattire flat_tire google gps heart_rate helmet history houston html humor journal kate kenpo_x kettlebell knees lazy legs lisa lisanne maps math matthew michaelmckenna mom montreal motivation movie mysql oops orm P90X pain park patellar_tendonitis patrick perl phb photos physical_therapy plyometrics poor_gait presentation procrastination pullups pushups pyramid rabbits racecondition rant refactor rest ribs ride route running shoulders situps slides sore spike sql statistics syntax test testing textile timex training triceps ups versioncontrol video vim vimrc walk warren work workouts yapc yapcna2007 yoga youtube

A R C H I V E S

(5)
(15)
(16)
(25)
(3)
(4)
(2)
(4)
(11)
(1)
(1)
(3)
(2)
(2)
(10)
(5)
(2)
(3)
(4)
(9)
(21)
(3)
(3)
(1)
(6)
(4)
(1)
(4)
(3)
(2)
(1)

    Is Kent Cowgill Online?
    View Kent Cowgill's profile on LinkedIn
    Add to Technorati Favorites

    Recent Entries...

    On track so far...

    The week is about half way over, and so far I haven't skippe...

    My pants are on fire!

    I lied. Friday evening I didn't do anything. Saturday ...

    Playing catch-up

    It's been a while since I've updated my P90X progress. A ...

    Re: Yoga kicks my butt

    You should try a different yoga mat. I highly recommend the...

    Yoga kicks my butt

    It's time for a confession. I haven't done an entire Yoga...

    Recovery week comes in the nick of time

    Since it's been a few days, and I know I've rearranged my in...

    Early to Bed, Early to Rise

    So I'm not exceptionally healthier, wealthier, or wiser. Bu...

    Chest and Back, week 3

    Sure, the date that's listed for this post is 10/28, but it'...

    No Procrastination, Some Pain, Some Gain

    After much cajoling and self-flagellation, I convinced mysel...

    Odd Math

    I must be counting something wrong. Granted, I haven't be...

    weblog | `web·lôg -läg |
    noun
    Another term for BLOG
    ORIGIN 1990s: from web in the sense [World Wide Web] and log in the sense [regular record of incidents.]
    blog | bläg |
    noun
    A web site on which an individual or group of users produces an ongoing narrative.
    ORIGIN a shortening of WEBLOG.

    Picking too fine a nit?

    Kent Cowgill

    So, I'm dutifully going through some 129 modules in our codebase, creating documentation and tests for everything I find.

    I mean absolutely everything.

    But I wonder if I'm going too far?

    For instance, I happened upon a module called Boolean.pm. Seems like it ought to be fairly low-hanging fruit, so I open it up to find that the whole of the module looks like this:

    
    package Boolean;
    use strict;
    use base q(Exporter);
    @Boolean::EXPORT = qw(TRUE FALSE);
    
    use constant TRUE  => 1;
    use constant FALSE => 0;
    
    1;
    __END__
    
    
    

    No joke.

    Fine, the tests will be easy enough. I won't repeat them here for brevity, but suffice it to say that the only thing that threw me for a loop is that use_ok didn't seem to import the exported constants into the namespace of my test file - after testing the module, I just use Boolean; and then I can test the constants. Could I have just called import as the module inherited from Exporter? Probably, but I didn't.

    The next module I come across is another top level namespace module named Database.pm. Whose primary purpose is to figure out which database server to have the rest of the code connect to, depending on a few external conditions. Part of the module declares a number of constants - the database connection strings - for internal (to the module) use only, and doesn't use base 'Exporter' and subsequently export those constants. However, it makes sense to me that I ought to test those constants as part of my test suite.

    So, fresh with my knowledge that constants aren't imported into the test file's namespace via use_ok, I add a use Database; and expect my tests to pass. Oops, not so fast - because I'm testing the constants as barewords, and they're not exported via @EXPORT, they're not recognized as constants and my test file (with use strict at the top) fails miserably complaining about my usage of barewords.

    So, what to do?

    I decided I would force the Database module to be @ISA = 'Exporter' and add the constants to @EXPORT myself, on behalf of the module, in the test file. So now my test file looks a bit like this:

    
    use strict;
    use warnings;
    
    use Test::More tests => 2;
    
    BEGIN {
      use Exporter;
      @Database::ISA = ( 'Exporter' );
      @Database::EXPORT = qw/PROD DEV/;
    }
    
    use_ok( 'Database' );
    
    use Database;
    
    is( PROD, 'production:dsn:etc',
        'PROD points to correct db' );
    is( DEV, 'development:dsn:etc',
        'DEV points to correct db' );
    
    
    

    ... but I have to wonder if this is worth all the bother. I suppose for now I'll leave it.

    Related Photos: perl

    Main Page | Login

    Do you want to buy me ? Find more gift ideas at my wishlist