Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of jjore (6662)

Tuesday October 03, 2006
02:18 PM

An even bester Best.pm

[ #31208 ]

http://search.cpan.org/dist/Best 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' );

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.