| 1 | package AutoSplit;
|
|---|
| 2 |
|
|---|
| 3 | use 5.006_001;
|
|---|
| 4 | use Exporter ();
|
|---|
| 5 | use Config qw(%Config);
|
|---|
| 6 | use Carp qw(carp);
|
|---|
| 7 | use File::Basename ();
|
|---|
| 8 | use File::Path qw(mkpath);
|
|---|
| 9 | use File::Spec::Functions qw(curdir catfile catdir);
|
|---|
| 10 | use strict;
|
|---|
| 11 | our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen,
|
|---|
| 12 | $CheckForAutoloader, $CheckModTime);
|
|---|
| 13 |
|
|---|
| 14 | $VERSION = "1.04";
|
|---|
| 15 | @ISA = qw(Exporter);
|
|---|
| 16 | @EXPORT = qw(&autosplit &autosplit_lib_modules);
|
|---|
| 17 | @EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);
|
|---|
| 18 |
|
|---|
| 19 | =head1 NAME
|
|---|
| 20 |
|
|---|
| 21 | AutoSplit - split a package for autoloading
|
|---|
| 22 |
|
|---|
| 23 | =head1 SYNOPSIS
|
|---|
| 24 |
|
|---|
| 25 | autosplit($file, $dir, $keep, $check, $modtime);
|
|---|
| 26 |
|
|---|
| 27 | autosplit_lib_modules(@modules);
|
|---|
| 28 |
|
|---|
| 29 | =head1 DESCRIPTION
|
|---|
| 30 |
|
|---|
| 31 | This function will split up your program into files that the AutoLoader
|
|---|
| 32 | module can handle. It is used by both the standard perl libraries and by
|
|---|
| 33 | the MakeMaker utility, to automatically configure libraries for autoloading.
|
|---|
| 34 |
|
|---|
| 35 | The C<autosplit> interface splits the specified file into a hierarchy
|
|---|
| 36 | rooted at the directory C<$dir>. It creates directories as needed to reflect
|
|---|
| 37 | class hierarchy, and creates the file F<autosplit.ix>. This file acts as
|
|---|
| 38 | both forward declaration of all package routines, and as timestamp for the
|
|---|
| 39 | last update of the hierarchy.
|
|---|
| 40 |
|
|---|
| 41 | The remaining three arguments to C<autosplit> govern other options to
|
|---|
| 42 | the autosplitter.
|
|---|
| 43 |
|
|---|
| 44 | =over 2
|
|---|
| 45 |
|
|---|
| 46 | =item $keep
|
|---|
| 47 |
|
|---|
| 48 | If the third argument, I<$keep>, is false, then any
|
|---|
| 49 | pre-existing C<*.al> files in the autoload directory are removed if
|
|---|
| 50 | they are no longer part of the module (obsoleted functions).
|
|---|
| 51 | $keep defaults to 0.
|
|---|
| 52 |
|
|---|
| 53 | =item $check
|
|---|
| 54 |
|
|---|
| 55 | The
|
|---|
| 56 | fourth argument, I<$check>, instructs C<autosplit> to check the module
|
|---|
| 57 | currently being split to ensure that it includes a C<use>
|
|---|
| 58 | specification for the AutoLoader module, and skips the module if
|
|---|
| 59 | AutoLoader is not detected.
|
|---|
| 60 | $check defaults to 1.
|
|---|
| 61 |
|
|---|
| 62 | =item $modtime
|
|---|
| 63 |
|
|---|
| 64 | Lastly, the I<$modtime> argument specifies
|
|---|
| 65 | that C<autosplit> is to check the modification time of the module
|
|---|
| 66 | against that of the C<autosplit.ix> file, and only split the module if
|
|---|
| 67 | it is newer.
|
|---|
| 68 | $modtime defaults to 1.
|
|---|
| 69 |
|
|---|
| 70 | =back
|
|---|
| 71 |
|
|---|
| 72 | Typical use of AutoSplit in the perl MakeMaker utility is via the command-line
|
|---|
| 73 | with:
|
|---|
| 74 |
|
|---|
| 75 | perl -e 'use AutoSplit; autosplit($ARGV[0], $ARGV[1], 0, 1, 1)'
|
|---|
| 76 |
|
|---|
| 77 | Defined as a Make macro, it is invoked with file and directory arguments;
|
|---|
| 78 | C<autosplit> will split the specified file into the specified directory and
|
|---|
| 79 | delete obsolete C<.al> files, after checking first that the module does use
|
|---|
| 80 | the AutoLoader, and ensuring that the module is not already currently split
|
|---|
| 81 | in its current form (the modtime test).
|
|---|
| 82 |
|
|---|
| 83 | The C<autosplit_lib_modules> form is used in the building of perl. It takes
|
|---|
| 84 | as input a list of files (modules) that are assumed to reside in a directory
|
|---|
| 85 | B<lib> relative to the current directory. Each file is sent to the
|
|---|
| 86 | autosplitter one at a time, to be split into the directory B<lib/auto>.
|
|---|
| 87 |
|
|---|
| 88 | In both usages of the autosplitter, only subroutines defined following the
|
|---|
| 89 | perl I<__END__> token are split out into separate files. Some
|
|---|
| 90 | routines may be placed prior to this marker to force their immediate loading
|
|---|
| 91 | and parsing.
|
|---|
| 92 |
|
|---|
| 93 | =head2 Multiple packages
|
|---|
| 94 |
|
|---|
| 95 | As of version 1.01 of the AutoSplit module it is possible to have
|
|---|
| 96 | multiple packages within a single file. Both of the following cases
|
|---|
| 97 | are supported:
|
|---|
| 98 |
|
|---|
| 99 | package NAME;
|
|---|
| 100 | __END__
|
|---|
| 101 | sub AAA { ... }
|
|---|
| 102 | package NAME::option1;
|
|---|
| 103 | sub BBB { ... }
|
|---|
| 104 | package NAME::option2;
|
|---|
| 105 | sub BBB { ... }
|
|---|
| 106 |
|
|---|
| 107 | package NAME;
|
|---|
| 108 | __END__
|
|---|
| 109 | sub AAA { ... }
|
|---|
| 110 | sub NAME::option1::BBB { ... }
|
|---|
| 111 | sub NAME::option2::BBB { ... }
|
|---|
| 112 |
|
|---|
| 113 | =head1 DIAGNOSTICS
|
|---|
| 114 |
|
|---|
|
|---|