Flylib.com

Books Software

 
 
 

Section A.17. Answers for Chapter 18


A.17. Answers for Chapter 18

A.17.1. Exercise 1

Since you're starting with your distribution from the last chapter, we don't have much code to show you. To add a POD test, create a t/pod.t file (or whatever you want to call it). In there, put the code you lift for Test::Pod :

use Test::More;
eval "use Test::Pod 1.00";
plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
all_pod_files_ok(  );

This code is clever: it only runs tests if the user has installed Test::Pod , and doesn't cause any problems if she hasn't.

If you are especially motivated, you can do the same thing with Test::Pod::Coverage . Create a t/pod_coverage.t file and lift the code directly from the module documentation.

Depending on which module creation tool you used, you might already have these files, too.

A.17.2. Exercise 2

You could create a new distribution for your test module, but you don't have to. You can include it with the distribution that you already made. You just have to put the module file in the right place and ensure that Makefile.PL or Build.PL knows about it.

We'll just show you the code, though. This is a long way to go to test $n = = $m , but we wanted to make it as uncomplicated as possible so you could focus on the Test::Builder part. You can lift most of the code directly from the example in the chapter and then write the sum_ok function.

package Test::My::List::Util;
use strict;

use base qw(Exporter);
use vars qw(@EXPORT $VERSION);

use Exporter;
use Test::Builder;

my $Test = Test::Builder->new(  );

$VERSION = '0.10';
@EXPORT  = qw(sum_ok);

sub sum_ok {
        my( $actual, $expected ) = @_;

        if( $actual =  = $expected ) {
                $Test->ok( 1 )
                }
        else {
                $Test->diag(
                        "The sum is not right\n",
                        "\tGot:      $actual\n",
                        "\tExpected: $expected\n"
                        );

                $Test->ok( 0 )
                }
        }

1;



A.18. Answer for Chapter 19

A.18.1. Exercise

Were you able to solve the halting problem? We didn't really expect you to solve this problem since, in 1936, Alan Turing proved you couldn't create a general solution. You can read about the halting problem at Wikipedia: http://en.wikipedia.org/wiki/Halting_problem.

There's not much we can show you as an answer to an exercise about distributions. You know about testing now, so as long as your tests pass, you know you're doing the right thing (or the tests don't work!).

We're kicking you out into the real world now. We don't have anything left to tell you in this book. Go back and read the footnotes now. Good luck!



About the Author

Randal L. Schwartz is a renowned expert on the Perl programming language. In addition to writing Learning Perl and the first two editions of Programming Perl , he has been the Perl columnist for UNIX Review , Web Techniques , Sys Admin , and Linux Magazine . He has contributed to a dozen Perl books and over 200 magazine articles. Randal runs a Perl training and consulting company(Stonehenge Consulting Services) and is highlysought after as a speaker for his combination of technical skill, comedic timing, and crowd rapport. He's also a pretty good Karaoke singer .

brian d foy has been an instructor for Stonehenge Consulting Services since 1998. He founded the first Perl user group , the New York Perl Mongers, as well as the Perl advocacynonprofit Perl Mongers, Inc., which helped form more than 200 Perl user groups across the globe. He maintains the perlfaq portions of the core Perl documentation, several modules on CPAN, and some standalone scripts. He's the publisher of The Perl Review and is a frequent speaker at conferences. His writings on Perl appear on The O'Reilly Network and use.perl.org, and in The Perl Journal , Dr. Dobbs Journal , and The Perl Review .

Tom Phoenix has been working in the field of education since 1982. After more than 13 years of dissections, explosions, work with interesting animals, and high-voltage sparks during his work at a science museum, he started teaching Perl for Stonehenge Consulting Services, where he's worked since 1996. As it is traditional for Perl people to have at least three other unlikely interests, Tom enjoys amateur cryptography, Esperanto, and Squeak (Smalltalk). According to rumor, he has never turned down an opportunityto playa game of Zendo. He lives in Portland, Oregon, with his wife and cats.