An even bester Best.pm

jjore on 2006-10-03T19:18:49

has learned several new things in the past few days. Best 0.07 and lower would just take a list of module names, an optional import list and load which ever succeeded.

The newest Best (0.08+) allows you to specify a minimum version, arbitrary pre- and post-loading criteria, per-module import lists, and substitute your own arbitrary code for perl modules.

Each one of these features addresses something I've solved in adhoc ways in the past but wished there were a standard way. Now there is. Yay!

PS, Gaal rocks.

  • Minimum versions
    use Best( 'Foo::Better' => 1.02,
              'Foo::Worse' );
    
    use Best( 'Foo::Better' => { version => 1.02 },
              'Foo::Worse' );
    
  • Pre- and post-loading criteria
    # pre-loading check
    use Best( 'Foo::Better' => { if => sub { $] >= 5.008 } },
              'Foo::Worse' );
    
    # post-loading check
    use Best( 'Foo::Better' => { ok => sub { defined &some_import } },
              'Foo::Worse' );
    
  • Per module import lists
    use Best( 'Foo::Better' => { args => [ ... ] },
              'Foo::Worse' );
    
  • Anything goes - arbitrary code
    use Best( sub {
                  return eval {
                      require Foo::Better;
                      if ( Foo::Better->can( ... ) ) {
                          return 1; # PASS
                      }
                      else {
                          return; # FAIL
                      }
                  };
              },
              'Foo::Worse' );