Letting the User Decide (Continued)

     

Letting the User Decide (Continued)

Module::Build provides a prompt( ) method that takes the same arguments as the prompt( ) function exported by ExtUtils::MakeMaker . However, this prompt( ) is a method, so either call it on the Module::Build class or a Module::Build or subclass object.

Module::Build also provides a y_n( ) method that returns either true or false, to simplify asking boolean questions. The y_n( ) method takes the same arguments as prompt( ) , except that the default answer, if supplied, must be either y or n .

How do I do that?

The Build.PL file for the MD5::Solve module is:

 use strict;     use warnings;     use Module::Build;     print "=  => Running the extended test suite may take weeks or years! <=  =\n";     my $answer = Module::Build->y_n(         'Do you want to run the extended test suite?', 'n'     );     my $patterns = 't/*.t';     if ($answer)     {         print "I'm going to run the extended tests.\n";         $patterns .= ' t/long/*.t';     }     else     {         print "Skipping extended tests.\n";     }     my $builder = Module::Build->new(         module_name       => 'MD5::Solve',         license           => 'perl',         dist_author       => 'Emily Anne Perlmonger <emmils@example.com>',         dist_version_from => 'lib/MD5/Solve.pm',         build_requires    => { 'Test::More' => 0, },         add_to_cleanup    => ['MD5-Solve-*'],         test_files        => $patterns,     );     $builder->create_build_script(  ); 


Note: Module::Build automatically expands the pattern(s) of files given to test_files .

Run Build.PL to see:

 $  perl Build.PL  =  => Running the extended test suite may take weeks or years! <=  =      Do you want to run the extended test suite? [n]  n  Skipping extended tests.     Checking whether your kit is complete...     Looks good     Creating new 'Build' script for 'MD5-Solve' version '0.01' 

What just happened ?

Similar to the Makefile.PL example earlier, the build script prompts the user whether to run the extended tests. If the user responds positively, $answer will be true, and the code will append t/long/*.t to the list of patterns of files to run in the test suite. Otherwise, only test files matching t/*.t will run during make test .



Perl Testing. A Developer's Notebook
Perl Testing: A Developers Notebook
ISBN: 0596100922
EAN: 2147483647
Year: 2003
Pages: 107

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net