目錄

名稱

AutoSplit - 自動載入的套件分割

語法

autosplit($file, $dir, $keep, $check, $modtime);

autosplit_lib_modules(@modules);

說明

此函式會將您的程式分割成 AutoLoader 模組可以處理的檔案。標準 perl 函式庫和 MakeMaker 工具程式都會使用它,以自動設定函式庫進行自動載入。

autosplit 介面會將指定檔案分割成以 $dir 目錄為根目錄的階層結構。它會視需要建立目錄來反映類別階層,並建立檔案 autosplit.ix。此檔案同時作為所有套件常式的向前宣告,以及階層結構最後更新的時間戳記。

autosplit 的另外三個引數控制自動分割器的其他選項。

$keep

如果第三個引數 $keep 為 false,則自動載入目錄中任何現有的 *.al 檔案,如果它們不再是模組的一部分(過時的函式),就會被移除。$keep 預設為 0。

$check

第四個引數 $check 指示 autosplit 檢查目前正在分割的模組,以確保它包含 AutoLoader 模組的 use 規格,如果未偵測到 AutoLoader,則略過該模組。$check 預設為 1。

$modtime

最後,$modtime 引數指定 autosplit 要根據模組的修改時間與 autosplit.ix 檔案的修改時間進行檢查,並且只在模組較新的情況下才分割模組。$modtime 預設為 1。

Perl MakeMaker 函式庫中 AutoSplit 的典型用法是透過命令列,使用

perl -e 'use AutoSplit; autosplit($ARGV[0], $ARGV[1], 0, 1, 1)'

定義為 Make 巨集,它會搭配檔案和目錄引數呼叫;autosplit 會將指定的檔案分割到指定的目錄,並刪除過時的 .al 檔案,在先檢查模組是否使用 AutoLoader,並確保模組目前尚未以目前的格式分割(modtime 測試)。

autosplit_lib_modules 格式用於建立 perl。它會將假設存在於目前目錄相對應的 lib 目錄中的檔案(模組)清單作為輸入。每次會將每個檔案傳送給自動分割程式,分割到目錄 lib/auto

在自動分割程式的兩種用法中,只有在 perl __END__ 標記之後定義的子常式會分割到個別檔案。有些常式可能會放置在此標記之前,以強制立即載入和剖析。

多個套件

從 AutoSplit 模組的 1.01 版開始,可以在單一檔案中有多個套件。以下兩種情況都受支援

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 { ... }

診斷

如果需要建立呼叫中指定的頂層目錄,AutoSplit 會通知使用者。建議呼叫 AutoSplit 的指令碼或安裝程序事先建立完整的目錄路徑。此警告可能表示模組分割到不正確的路徑。

AutoSplit 會警告使用者所有子常式名稱,這些名稱會導致檔案命名衝突,發生在檔案名稱長度極短(8 個字元或更少)的電腦上。由於子常式名稱用作檔案名稱,這些警告有助於移植到此類系統。

如果 AutoSplit 找不到 __END__ 標記或「套件 Name;」樣式的規格,就會發出警告並略過檔案。

AutoSplit 也會針對無法建立目錄或檔案發出一般診斷。

作者

AutoSplit 由 perl5-porters 維護。請將任何問題導向正規郵件清單。不過,任何適用於 CPAN 版本的內容都可以傳送給其維護人員。

作者和維護人員:Perl5-Porters <perl5-porters@perl.org>

CPAN 版本的維護人員:Steffen Mueller <smueller@cpan.org>

著作權和授權

這個套件自 perl5 首次發布以來,便一直是 perl 核心的一部分。它已獨立發布至 CPAN,以便舊版安裝可以從錯誤修正中受益。

這個套件擁有與 perl 核心相同的版權和授權。

             Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
        2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
        by Larry Wall and others
    
			    All rights reserved.
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of either:
    
	a) the GNU General Public License as published by the Free
	Software Foundation; either version 1, or (at your option) any
	later version, or
    
	b) the "Artistic License" which comes with this Kit.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
    the GNU General Public License or the Artistic License for more details.
    
    You should have received a copy of the Artistic License with this
    Kit, in the file named "Artistic".  If not, I'll be glad to provide one.
    
    You should also have received a copy of the GNU General Public License
    along with this program in the file named "Copying". If not, write to the 
    Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
    02111-1307, USA or visit their web page on the internet at
    https://gnu.dev.org.tw/copyleft/gpl.html.
    
    For those of you that choose to use the GNU General Public License,
    my interpretation of the GNU General Public License is that no Perl
    script falls under the terms of the GPL unless you explicitly put
    said script under the terms of the GPL yourself.  Furthermore, any
    object code linked with perl does not automatically fall under the
    terms of the GPL, provided such object code only adds definitions
    of subroutines and variables, and does not otherwise impair the
    resulting interpreter from executing any standard Perl script.  I
    consider linking in C subroutines in this manner to be the moral
    equivalent of defining subroutines in the Perl language itself.  You
    may sell such an object file as proprietary provided that you provide
    or offer to provide the Perl source, as specified by the GNU General
    Public License.  (This is merely an alternate way of specifying input
    to the program.)  You may also sell a binary produced by the dumping of
    a running Perl script that belongs to you, provided that you provide or
    offer to provide the Perl source as specified by the GPL.  (The
    fact that a Perl interpreter and your code are in the same binary file
    is, in this case, a form of mere aggregation.)  This is my interpretation
    of the GPL.  If you still have concerns or difficulties understanding
    my intent, feel free to contact me.  Of course, the Artistic License
    spells all this out for your protection, so you may prefer to use that.