| 1 | # -*- Mode: perl -*- | ||
| 2 | # | ||
| 3 | # $Id: MakeMaker.pm,v 0.1 2001/03/31 10:04:36 ram Exp $ | ||
| 4 | # | ||
| 5 | # Copyright (c) 2000-2001, Christophe Dehaudt & Raphael Manfredi | ||
| 6 | # | ||
| 7 | # You may redistribute only under the terms of the Artistic License, | ||
| 8 | # as specified in the README file that comes with the distribution. | ||
| 9 | # | ||
| 10 | # HISTORY | ||
| 11 | # $Log: MakeMaker.pm,v $ | ||
| 12 | # Revision 0.1 2001/03/31 10:04:36 ram | ||
| 13 | # Baseline for first Alpha release. | ||
| 14 | # | ||
| 15 | # $EndLog$ | ||
| 16 | # | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | |||
| 20 | package Carp::Datum::MakeMaker; | ||
| 21 | |||
| 22 | use Log::Agent; | ||
| 23 | |||
| 24 | require Exporter; | ||
| 25 | use vars qw(@ISA @EXPORT); | ||
| 26 | @ISA = qw(Exporter); | ||
| 27 | @EXPORT = qw(WriteMakefile); | ||
| 28 | |||
| 29 | require ExtUtils::MakeMaker; | ||
| 30 | |||
| 31 | # | ||
| 32 | # ->WriteMakefile | ||
| 33 | # | ||
| 34 | # Supersedes the version from ExtUtils::MakeMaker to get a chance to ask | ||
| 35 | # whether the debugging version of the module needs to be installed or not. | ||
| 36 | # This is only possible starting with version 5.45 of MakeMaker (perl 5.6.1). | ||
| 37 | # | ||
| 38 | sub WriteMakefile { | ||
| 39 | my %args = @_; | ||
| 40 | my $version = $ExtUtils::MakeMaker::VERSION; | ||
| 41 | my $name = $args{NAME}; | ||
| 42 | my $LIMIT = 5.45; | ||
| 43 | |||
| 44 | if ($version < $LIMIT) { | ||
| 45 | print "Keeping Carp::Datum calls in $name -- MakeMaker is too old\n"; | ||
| 46 | print "(Would need ExtUtils::MakeMaker version $LIMIT or better)\n"; | ||
| 47 | return &ExtUtils::MakeMaker::WriteMakefile; | ||
| 48 | } elsif (-t STDIN) { | ||
| 49 | local *TTY; | ||
| 50 | open(TTY, ">/dev/tty"); | ||
| 51 | select((select(TTY), $| = 1)[0]); | ||
| 52 | print TTY <<EOM; | ||
| 53 | |||
| 54 | The $name module uses the Carp::Datum extension to implement the | ||
| 55 | Programming by Contract paradigm, and also get flexible tracing abilities. | ||
| 56 | |||
| 57 | By default, I shall strip all the Carp::Datum stuff at build time, and | ||
| 58 | you will get a clean copy, almost as if the author of $name had never | ||
| 59 | used Carp::Datum in the first place. Only DTRACE calls will be kept, | ||
| 60 | and will be redirected at runtime to Log::Agent. | ||
| 61 | |||
| 62 | Or you can choose to install the debugging version. However, unless your | ||
| 63 | application explicitely requests debugging, Carp::Datum will remain silent, | ||
| 64 | only monitoring the assertions. The exact runtime penalty you will suffer | ||
| 65 | depends on the amount of assertions, but it is around 15%. | ||
| 66 | |||
| 67 | EOM | ||
| 68 | print TTY "Strip Carp::Datum calls in installed $name? [y] "; | ||
| 69 | close TTY; | ||
| 70 | my $ans = <STDIN>; | ||
| 71 | return &ExtUtils::MakeMaker::WriteMakefile if $ans =~ /^n/i; | ||
| 72 | } else { | ||
| 73 | print "Will build $name with calls to Carp::Datum stripped\n"; | ||
| 74 | } | ||
| 75 | |||
| 76 | # | ||
| 77 | # They wish to remove all Carp::Datum code from the installed files. | ||
| 78 | # | ||
| 79 | |||
| 80 | $args{'macro'} = {} unless exists $args{'macro'}; | ||
| 81 | $args{'macro'}->{PM_FILTER} = "datum_strip"; | ||
| 82 | |||
| 83 | return &ExtUtils::MakeMaker::WriteMakefile(%args); | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; | ||
| 87 | |||
| 88 | =head1 NAME | ||
| 89 | |||
| 90 | Carp::Datum::MakeMaker - Offer to strip Carp::Datum calls statically | ||
| 91 | |||
| 92 | =head1 SYNOPSIS | ||
| 93 | |||
| 94 | # Put this at the top of the Makefile.PL for your module | ||
| 95 | use ExtUtils::MakeMaker; # you may omit this line | ||
| 96 | use Carp::Datum::MakeMaker; | ||
| 97 | |||
| 98 | =head1 DESCRIPTION | ||
| 99 | |||
| 100 | The C<Carp::Datum::MakeMaker> module supersedes the regular WriteMakefile() | ||
| 101 | routine of C<ExtUtils::MakeMaker>. | ||
| 102 | |||
| 103 | When running the Makefile.PL from a module interactively, the user will | ||
| 104 | be asked whether calls to C<Carp::Datum> should be stripped at build time. | ||
| 105 | |||
| 106 | By default, or when running non-interactively, most calls to Carp::Datum | ||
| 107 | routines will be removed: | ||
| 108 | the C<datum_strip> program will be invoked to filter *.pm files during | ||
| 109 | the build process. This program is a mere wrapper for the datum_strip() | ||
| 110 | routine, defined in C<Carp::Datum::Strip>. | ||
| 111 | |||
| 112 | The only call that will not be stripped is the DTRACE() call. However, it | ||
| 113 | will be dynamically remapped to a C<Log::Agent> call. It cannot be statically | ||
| 114 | remapped because of its baroque interface. | ||
| 115 | |||
| 116 | At the top of Makefile.PL, insert | ||
| 117 | |||
| 118 | use Carp::Datum::MakeMaker; | ||
| 119 | |||
| 120 | which will take care of loading C<ExtUtils::MakeMaker>. Note that | ||
| 121 | it makes sense to refer to this module, since C<Carp::Datum> is being used | ||
| 122 | internally, and therefore the user will not be able to install the module | ||
| 123 | if they do not have C<Carp::Datum> already installed. | ||
| 124 | |||
| 125 | If you wish to be nicer about C<Carp::Datum> not being installed, you | ||
| 126 | can say instead: | ||
| 127 | |||
| 128 | use ExtUtils::MakeMaker; | ||
| 129 | eval "use Carp::Datum::MakeMaker;"; | ||
| 130 | |||
| 131 | WriteMakefile( | ||
| 132 | 'NAME' => "Your::module::name", | ||
| 133 | 'PREREQ_PM' => { | ||
| 134 | 'Carp::Datum' => '0.100', | ||
| 135 | }, | ||
| 136 | ); | ||
| 137 | |||
| 138 | It will allow them to run the Makefile.PL, and yet be reminded about the | ||
| 139 | missing C<Carp::Datum> module. Chances are they won't be able to go | ||
| 140 | much farther though... | ||
| 141 | |||
| 142 | =head1 AUTHORS | ||
| 143 | |||
| 144 | Christophe Dehaudt and Raphael Manfredi are the original authors. | ||
| 145 | |||
| 146 | Send bug reports, hints, tips, suggestions to Dave Hoover at <squirrel@cpan.org>. | ||
| 147 | |||
| 148 | =head1 SEE ALSO | ||
| 149 | |||
| 150 | Carp::Datum::Strip(3), ExtUtils::MakeMaker(3). | ||
| 151 | |||
| 152 | =cut | ||
| 153 |