autosplit.pm
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PM 代码 · 共 523 行 · 第 1/2 页
PM
523 行
package AutoSplit;use Exporter ();use Config qw(%Config);use File::Basename ();use File::Path qw(mkpath);use File::Spec::Functions qw(curdir catfile catdir);use strict;our($VERSION, @ISA, @EXPORT, @EXPORT_OK, $Verbose, $Keep, $Maxlen, $CheckForAutoloader, $CheckModTime);$VERSION = "1.05";@ISA = qw(Exporter);@EXPORT = qw(&autosplit &autosplit_lib_modules);@EXPORT_OK = qw($Verbose $Keep $Maxlen $CheckForAutoloader $CheckModTime);=head1 NAMEAutoSplit - split a package for autoloading=head1 SYNOPSIS autosplit($file, $dir, $keep, $check, $modtime); autosplit_lib_modules(@modules);=head1 DESCRIPTIONThis function will split up your program into files that the AutoLoadermodule can handle. It is used by both the standard perl libraries and bythe MakeMaker utility, to automatically configure libraries for autoloading.The C<autosplit> interface splits the specified file into a hierarchy rooted at the directory C<$dir>. It creates directories as needed to reflectclass hierarchy, and creates the file F<autosplit.ix>. This file acts asboth forward declaration of all package routines, and as timestamp for thelast update of the hierarchy.The remaining three arguments to C<autosplit> govern other options tothe autosplitter.=over 2=item $keepIf the third argument, I<$keep>, is false, then anypre-existing C<*.al> files in the autoload directory are removed ifthey are no longer part of the module (obsoleted functions).$keep defaults to 0.=item $checkThefourth argument, I<$check>, instructs C<autosplit> to check the modulecurrently being split to ensure that it includes a C<use>specification for the AutoLoader module, and skips the module ifAutoLoader is not detected.$check defaults to 1.=item $modtimeLastly, the I<$modtime> argument specifiesthat C<autosplit> is to check the modification time of the moduleagainst that of the C<autosplit.ix> file, and only split the module ifit is newer.$modtime defaults to 1.=backTypical use of AutoSplit in the perl MakeMaker utility is via the command-linewith: perl -e 'use AutoSplit; autosplit($ARGV[0], $ARGV[1], 0, 1, 1)'Defined as a Make macro, it is invoked with file and directory arguments;C<autosplit> will split the specified file into the specified directory anddelete obsolete C<.al> files, after checking first that the module does usethe AutoLoader, and ensuring that the module is not already currently splitin its current form (the modtime test).The C<autosplit_lib_modules> form is used in the building of perl. It takesas input a list of files (modules) that are assumed to reside in a directoryB<lib> relative to the current directory. Each file is sent to the autosplitter one at a time, to be split into the directory B<lib/auto>.In both usages of the autosplitter, only subroutines defined following theperl I<__END__> token are split out into separate files. Someroutines may be placed prior to this marker to force their immediate loadingand parsing.=head2 Multiple packagesAs of version 1.01 of the AutoSplit module it is possible to havemultiple packages within a single file. Both of the following casesare supported: package NAME; __END__ sub AAA { ... } package NAME::option1; sub BBB { ... } package NAME::option2; sub BBB { ... } package NAME; __END__ sub AAA { ... } sub NAME::option1::BBB { ... } sub NAME::option2::BBB { ... }=head1 DIAGNOSTICSC<AutoSplit> will inform the user if it is necessary to create thetop-level directory specified in the invocation. It is preferred thatthe script or installation process that invokes C<AutoSplit> havecreated the full directory path ahead of time. This warning mayindicate that the module is being split into an incorrect path.C<AutoSplit> will warn the user of all subroutines whose name causespotential file naming conflicts on machines with drastically limited(8 characters or less) file name length. Since the subroutine name isused as the file name, these warnings can aid in portability to suchsystems.Warnings are issued and the file skipped if C<AutoSplit> cannot locateeither the I<__END__> marker or a "package Name;"-style specification.C<AutoSplit> will also emit general diagnostics for inability tocreate directories or files.=cut# for portability warn about names longer than $maxlen$Maxlen = 8; # 8 for dos, 11 (14-".al") for SYSVR3$Verbose = 1; # 0=none, 1=minimal, 2=list .al files$Keep = 0;$CheckForAutoloader = 1;$CheckModTime = 1;my $IndexFile = "autosplit.ix"; # file also serves as timestampmy $maxflen = 255;$maxflen = 14 if $Config{'d_flexfnam'} ne 'define';if (defined (&Dos::UseLFN)) { $maxflen = Dos::UseLFN() ? 255 : 11;}my $Is_VMS = ($^O eq 'VMS');# allow checking for valid ': attrlist' attachments.# extra jugglery required to support both 5.8 and 5.9/5.10 features# (support for 5.8 required for cross-compiling environments)my $attr_list = $] >= 5.009005 ? eval <<'__QR__' qr{ \s* : \s* (?: # one attribute (?> # no backtrack (?! \d) \w+ (?<nested> \( (?: [^()]++ | (?&nested)++ )*+ \) ) ? ) (?: \s* : \s* | \s+ (?! :) ) )* }x__QR__ : do { # In pre-5.9.5 world we have to do dirty tricks. # (we use 'our' rather than 'my' here, due to the rather complex and buggy # behaviour of lexicals with qr// and (??{$lex}) ) our $trick1; # yes, cannot our and assign at the same time. $trick1 = qr{ \( (?: (?> [^()]+ ) | (??{ $trick1 }) )* \) }x; our $trick2 = qr{ (?> (?! \d) \w+ (?:$trick1)? ) (?:\s*\:\s*|\s+(?!\:)) }x; qr{ \s* : \s* (?: $trick2 )* }x; };sub autosplit{ my($file, $autodir, $keep, $ckal, $ckmt) = @_; # $file - the perl source file to be split (after __END__) # $autodir - the ".../auto" dir below which to write split subs # Handle optional flags: $keep = $Keep unless defined $keep; $ckal = $CheckForAutoloader unless defined $ckal; $ckmt = $CheckModTime unless defined $ckmt; autosplit_file($file, $autodir, $keep, $ckal, $ckmt);}sub carp{ require Carp; goto &Carp::carp;}# This function is used during perl building/installation# ./miniperl -e 'use AutoSplit; autosplit_lib_modules(@ARGV)' ...sub autosplit_lib_modules { my(@modules) = @_; # list of Module names local $_; # Avoid clobber. while (defined($_ = shift @modules)) { while (m#([^:]+)::([^:].*)#) { # in case specified as ABC::XYZ $_ = catfile($1, $2); } s|\\|/|g; # bug in ksh OS/2 s#^lib/##s; # incase specified as lib/*.pm my($lib) = catfile(curdir(), "lib"); if ($Is_VMS) { # may need to convert VMS-style filespecs $lib =~ s#^\[\]#.\/#; } s#^$lib\W+##s; # incase specified as ./lib/*.pm if ($Is_VMS && /[:>\]]/) { # may need to convert VMS-style filespecs my ($dir,$name) = (/(.*])(.*)/s); $dir =~ s/.*lib[\.\]]//s; $dir =~ s#[\.\]]#/#g; $_ = $dir . $name; } autosplit_file(catfile($lib, $_), catfile($lib, "auto"), $Keep, $CheckForAutoloader, $CheckModTime); } 0;}# private functionsmy $self_mod_time = (stat __FILE__)[9];sub autosplit_file { my($filename, $autodir, $keep, $check_for_autoloader, $check_mod_time) = @_; my(@outfiles); local($_); local($/) = "\n"; # where to write output files $autodir ||= catfile(curdir(), "lib", "auto"); if ($Is_VMS) { ($autodir = VMS::Filespec::unixpath($autodir)) =~ s|/\z||; $filename = VMS::Filespec::unixify($filename); # may have dirs } unless (-d $autodir){ mkpath($autodir,0,0755); # We should never need to create the auto dir # here. installperl (or similar) should have done # it. Expecting it to exist is a valuable sanity check against # autosplitting into some random directory by mistake. print "Warning: AutoSplit had to create top-level " . "$autodir unexpectedly.\n"; } # allow just a package name to be used $filename .= ".pm" unless ($filename =~ m/\.pm\z/); open(my $in, "<$filename") or die "AutoSplit: Can't open $filename: $!\n"; my($pm_mod_time) = (stat($filename))[9]; my($autoloader_seen) = 0; my($in_pod) = 0; my($def_package,$last_package,$this_package,$fnr); while (<$in>) { # Skip pod text. $fnr++; $in_pod = 1 if /^=\w/;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?