ExtUtils-MakeMaker-6.17 > ExtUtils::MakeMaker::Tutorial
ExtUtils-MakeMaker-6.17
Other versions:
ExtUtils-MakeMaker-6.55_02

名前

ExtUtils::MakeMaker::Tutorial - Writing a module with MakeMaker

ExtUtils::MakeMaker::Tutorial - MakeMaker を使ったモジュールの書き方

概要

    use ExtUtils::MakeMaker;

    WriteMakefile(
        NAME            => 'Your::Module',
        VERSION_FROM    => 'lib/Your/Module.pm'
    );

説明

This is a short tutorial on writing a simple module with MakeMaker. Its really not that hard.

これは簡単なモジュールを MakeMaker を使って作成する手順の簡単な紹介です。 ここでは複雑なことは抜きに読むことができます。

呪文

MakeMaker modules are installed using this simple mantra

MakeMaker を使っているモジュールは次の魔法の言葉をつかって インストールできます。

        perl Makefile.PL
        make
        make test
        make install

There are lots more commands and options, but the above will do it.

もっと様々なコマンドやオプションも扱えますが、通常はこれだけで十分です。

レイアウト

The basic files in a module look something like this.

モジュール内の基本的なファイルは次のようなものです。

        Makefile.PL
        MANIFEST
        lib/Your/Module.pm

That's all that's strictly necessary. There's additional files you might want:

それらは厳密に必要とされています。 また、必要であれば以下のファイルを加えても良いでしょう:

        lib/Your/Other/Module.pm
        t/some_test.t
        t/some_other_test.t
        Changes
        README
        INSTALL
        MANIFEST.SKIP
        bin/some_program
Makefile.PL

When you run Makefile.PL, it makes a Makefile. That's the whole point of MakeMaker. The Makefile.PL is a simple module which loads ExtUtils::MakeMaker and runs the WriteMakefile() function with a few simple arguments.

Makefile.PL を実行すると Makefile が作成されます。 これが MakeMaker の全てです。 Makefile.PL は ExtUtils::MakeMaker をロードして WriteMakefile() 関数を わずかな引数で実行するだけの簡単なスクリプトです。

Here's an example of what you need for a simple module:

シンプルなモジュールでは次のようになります:

    use ExtUtils::MakeMaker;

    WriteMakefile(
        NAME            => 'Your::Module',
        VERSION_FROM    => 'lib/Your/Module.pm'
    );

NAME is the top-level namespace of your module. VERSION_FROM is the file which contains the $VERSION variable for the entire distribution. Typically this is the same as your top-level module.

NAME はインストールするモジュールのトップレベルの名前空間です。 VERSION_FROM は配布パッケージのに使うバージョン番号を取得するファイルです。 指定したファイル内の $VERSION 変数の値が 配布パッケージのバージョンとして使われます。 大抵トップレベルのモジュールのファイルと同じでしょう。

MANIFEST

A simple listing of all the files in your distribution.

配布するファイルの単純なリストです。

        Makefile.PL
        MANIFEST
        lib/Your/Module.pm

File paths in a MANIFEST always use Unix conventions (ie. /) even if you're not on Unix.

MANIFEST ファイル内のファイルパスは常に(例え Unix 以外の環境で 作成していても) Unix のもの (すなわち /) を使います。

You can write this by hand or generate it with 'make manifest'.

このファイルは手で記述することも、'make manifest' によって 生成することもできます。

lib/

This is the directory where your .pm and .pod files you wish to have installed go. They are layed out according to namespace. So Foo::Bar is lib/Foo/Bar.pm.

インストールする .pm 及び .pod ファイルを配置するディレクトリです。 各ファイルは名前空間に沿って配置します。 Foo::Base であれば lib/Foo/Bar.pm とします。

t/

Tests for your modules go here. Each test filename ends with a .t. So t/foo.t. 'make test' will run these tests. The directory is flat, you cannot, for example, have t/foo/bar.t run by 'make test'.

モジュールのテストを行うファイルを置きます。 各テストファイルの名前は .t で終わるようにします。 つまり t/foo.t になります。 これらのファイルは 'make test' によって実行されます。 ディレクトリ内にはフラットに配置してください; 例えば、 t/foo/bar.t の様なファイルは 'make test' では実行されません。

Tests are run from the top level of your distribution. So inside a test you would refer to ./lib to enter the lib directory, for example.

テストは配布パッケージ内のトップディレクトリで実行されます。 テストスクリプト内からは、例えば lib ディレクトリは ./lib で 参照することになります。

Changes

A log of changes you've made to this module. The layout is free-form. Here's an example:

モジュールに対して行われた様々な変更点。 書式は決まっていないのでお好みの形式で。 一例:

    1.01 Fri Apr 11 00:21:25 PDT 2003
        - thing() does some stuff now
        - fixed the wiggy bug in withit()

    1.00 Mon Apr  7 00:57:15 PDT 2003
        - "Rain of Frogs" now supported
README

A short description of your module, what it does, why someone would use it and its limitations. CPAN automatically pulls your README file out of the archive and makes it available to CPAN users, it is the first thing they will read to decide if your module is right for them.

モジュールの短い説明を書きます; このモジュールが何を行う物なのか、なぜ使うべきなのか、 使用に当たっての制限などを記述しておくと良いでしょう。 CPAN では README ファイルをアーカイブから自動的に取り出して CPAN ユーザに利用できるようにするので、これが作成したモジュールが CPAN の利用者たちに見てもらう最初の文章になります。

INSTALL

Instructions on how to install your module along with any dependencies. Suggested information to include here:

何らかの依存関係を持っている場合に、どの様にインストールすればよいかの 手順書です。 このファイルに記述しておくべき情報は以下の様になります:

    any extra modules required for use
    the minimum version of Perl required
    if only works on certain operating systems
    このモジュールには別の何かのモジュールを必要とします
    Perl が最低限必要です
    特定のOSで動作します
MANIFEST.SKIP

A file full of regular expressions to exclude when using 'make manifest' to generate the MANIFEST. These regular expressions are checked against each file path found in the distribution (so you're matching against "t/foo.t" not "foo.t").

'make manifest' を使って MANIFEST ファイルを生成するときに 対象外にするファイルを指定する完全な正規表現を記述します。 これらの正規表現はファイルパスに対して評価されます (つまり、"foo.t" ではなく "t/foo.t" に対してマッチングを 確認します)。

Here's a sample:

例:

    ~$          # ignore emacs and vim backup files
    .bak$       # ignore manual backups
    \#          # ignore CVS old revision files and emacs temp files

Since # can be used for comments, # must be escaped.

# はコメントの始まりとして扱われるので # 自体を マッチさせたいときにはエスケープしなければなりません。

MakeMaker comes with a default MANIFEST.SKIP to avoid things like version control directories and backup files. Specifying your own will override this default.

MakeMaker はバージョン管理ディレクトリやバックアップファイルを 無視するデフォルトの MANIFEST.SKIP をもっています。 自分用の MANIFEST.SKIP があるとデフォルトの指定は 上書きされます。

bin/

SEE ALSO

perlmodstyle gives stylistic help writing a module.

perlmodstyle にはモジュールを書く上での スタイル的なヘルプがあります。

perlnewmod gives more information about how to write a module.

perlnewmod にはモジュールの書き方に関するより多くの 情報があります。

There are modules to help you through the process of writing a module: ExtUtils::ModuleMaker, Module::Install, PAR

モジュールを作る作業全体を通して役立つモジュールもあります: ExtUtils::ModuleMaker, Module::Install, PAR