perlnewmod >
5.18.1
との差分
perlnewmod 5.18.1 と 5.20.1 の差分
1 | 1 | |
2 | 2 | =encoding euc-jp |
3 | 3 | |
4 | 4 | =head1 NAME |
5 | 5 | |
6 | 6 | =begin original |
7 | 7 | |
8 | 8 | perlnewmod - preparing a new module for distribution |
9 | 9 | |
10 | 10 | =end original |
11 | 11 | |
12 | 12 | perlnewmod - 新しいモジュールを配布するには |
13 | 13 | |
14 | 14 | =head1 DESCRIPTION |
15 | 15 | |
16 | 16 | =begin original |
17 | 17 | |
18 | 18 | This document gives you some suggestions about how to go about writing |
19 | 19 | Perl modules, preparing them for distribution, and making them available |
20 | 20 | via CPAN. |
21 | 21 | |
22 | 22 | =end original |
23 | 23 | |
24 | 24 | このドキュメントは、Perl モジュールを書き、配布する準備をして、CPAN を |
25 | 25 | 通じて取得可能にするためのアドバイスです。 |
26 | 26 | |
27 | 27 | =begin original |
28 | 28 | |
29 | 29 | One of the things that makes Perl really powerful is the fact that Perl |
30 | 30 | hackers tend to want to share the solutions to problems they've faced, |
31 | 31 | so you and I don't have to battle with the same problem again. |
32 | 32 | |
33 | 33 | =end original |
34 | 34 | |
35 | 35 | Perl が実際にこんなに強力な理由の 1 つとして、Perl ハッカーたちが、自分の |
36 | 36 | 直面した問題への解決策を共有しようとしていることが挙げられるでしょう; |
37 | 37 | だから、みんなが同じ問題に悩む必要はないわけです。 |
38 | 38 | |
39 | 39 | =begin original |
40 | 40 | |
41 | 41 | The main way they do this is by abstracting the solution into a Perl |
42 | 42 | module. If you don't know what one of these is, the rest of this |
43 | 43 | document isn't going to be much use to you. You're also missing out on |
44 | 44 | an awful lot of useful code; consider having a look at L<perlmod>, |
45 | 45 | L<perlmodlib> and L<perlmodinstall> before coming back here. |
46 | 46 | |
47 | 47 | =end original |
48 | 48 | |
49 | 49 | これが実現されているのは、多くの場合あるソリューションを抽象化して、 |
50 | 50 | Perl モジュールにしているということです。 |
51 | 51 | もしこれがなんのことかわからなければ、このドキュメントの残りはあまり |
52 | 52 | 役には立たないでしょうし、今までにたくさんの便利なコードを |
53 | 53 | 見逃していることでしょう。 |
54 | 54 | L<perlmod>, L<perlmodlib>, L<perlmodinstall> をよく読んで、ここに戻って |
55 | 55 | 来てください。 |
56 | 56 | |
57 | 57 | =begin original |
58 | 58 | |
59 | 59 | When you've found that there isn't a module available for what you're |
60 | 60 | trying to do, and you've had to write the code yourself, consider |
61 | 61 | packaging up the solution into a module and uploading it to CPAN so that |
62 | 62 | others can benefit. |
63 | 63 | |
64 | 64 | =end original |
65 | 65 | |
66 | 66 | もし、あなたがやるべきことに関するモジュールが存在せず、自分でコードを |
67 | 67 | 書かないといけないとなったときには、そのソリューションをモジュールに |
68 | 68 | 詰め込んで CPAN にアップロードすることを検討してください; |
69 | 69 | そうすれば、他のみんなの利益になります。 |
70 | 70 | |
71 | 71 | =head2 Warning |
72 | 72 | |
73 | 73 | (警告) |
74 | 74 | |
75 | 75 | =begin original |
76 | 76 | |
77 | 77 | We're going to primarily concentrate on Perl-only modules here, rather |
78 | 78 | than XS modules. XS modules serve a rather different purpose, and |
79 | 79 | you should consider different things before distributing them - the |
80 | 80 | popularity of the library you are gluing, the portability to other |
81 | 81 | operating systems, and so on. However, the notes on preparing the Perl |
82 | 82 | side of the module and packaging and distributing it will apply equally |
83 | 83 | well to an XS module as a pure-Perl one. |
84 | 84 | |
85 | 85 | =end original |
86 | 86 | |
87 | 87 | ここでは主にピュア Perl のモジュールについて説明し、XS モジュールについては |
88 | 88 | 触れません。 |
89 | 89 | XS モジュールは、通常とは若干異なる目的で利用されるため、配布する際には |
90 | 90 | 別の問題について考慮する必要があります; つまり、糊付け(glue)の対象となる |
91 | 91 | ライブラリの人気、他の OS へのポータビリティなどです。 |
92 | 92 | しかし、モジュールの準備やパッケージング、配布の説明は、XS モジュールにも |
93 | 93 | 同様に当てはまるでしょう。 |
94 | 94 | |
95 | 95 | =head2 What should I make into a module? |
96 | 96 | |
97 | 97 | (なにをモジュールにしたらいい?) |
98 | 98 | |
99 | 99 | =begin original |
100 | 100 | |
101 | 101 | You should make a module out of any code that you think is going to be |
102 | 102 | useful to others. Anything that's likely to fill a hole in the communal |
103 | 103 | library and which someone else can slot directly into their program. Any |
104 | 104 | part of your code which you can isolate and extract and plug into |
105 | 105 | something else is a likely candidate. |
106 | 106 | |
107 | 107 | =end original |
108 | 108 | |
109 | 109 | 他の人に便利になるものなら、どんなコードでもモジュールにするべきです。 |
110 | 110 | みんなが使っているライブラリに足りないものを補って、しかも他の人が自分の |
111 | 111 | プログラムに直接組み込めるものならなんでも OK です。 |
112 | 112 | あなたのコードのうち、単独でとりだして、他のものに組み込めるものがあれば、 |
113 | 113 | それはモジュールの候補になりえるでしょう。 |
114 | 114 | |
115 | 115 | =begin original |
116 | 116 | |
117 | 117 | Let's take an example. Suppose you're reading in data from a local |
118 | 118 | format into a hash-of-hashes in Perl, turning that into a tree, walking |
119 | 119 | the tree and then piping each node to an Acme Transmogrifier Server. |
120 | 120 | |
121 | 121 | =end original |
122 | 122 | |
123 | 123 | 例をとってみましょう。 |
124 | 124 | ローカルのフォーマットからデータを読みだし、Perl のハッシュリファレンスの |
125 | 125 | ハッシュにして、ツリー構造にして、ツリーを操作してそれぞれのノードを |
126 | 126 | Acme Transmogrifier Server にパイプするとします。 |
127 | 127 | |
128 | 128 | =begin original |
129 | 129 | |
130 | 130 | Now, quite a few people have the Acme Transmogrifier, and you've had to |
131 | 131 | write something to talk the protocol from scratch - you'd almost |
132 | 132 | certainly want to make that into a module. The level at which you pitch |
133 | 133 | it is up to you: you might want protocol-level modules analogous to |
134 | 134 | L<Net::SMTP|Net::SMTP> which then talk to higher level modules analogous |
135 | 135 | to L<Mail::Send|Mail::Send>. The choice is yours, but you do want to get |
136 | 136 | a module out for that server protocol. |
137 | 137 | |
138 | 138 | =end original |
139 | 139 | |
140 | 140 | さて、Acme Transmogrifier をもっている人はあんまりいないとしましょう; |
141 | 141 | ですから、そのプロトコルを話すコードをスクラッチから書く必要があるでしょう - |
142 | 142 | そんな時、それをモジュールにしたいはずです。 |
143 | 143 | どのレベルで操作するかはあなた次第です: L<Net::SMTP> のような |
144 | 144 | プロトコルレベルのモジュールから、L<Mail::Send> のような高レベルで |
145 | 145 | 操作するモジュールまで。 |
146 | 146 | 決定するのはあなたですが、サーバプロトコルに特化したモジュールを |
147 | 147 | 作りたいでしょう。 |
148 | 148 | |
149 | 149 | =begin original |
150 | 150 | |
151 | 151 | Nobody else on the planet is going to talk your local data format, so we |
152 | 152 | can ignore that. But what about the thing in the middle? Building tree |
153 | 153 | structures from Perl variables and then traversing them is a nice, |
154 | 154 | general problem, and if nobody's already written a module that does |
155 | 155 | that, you might want to modularise that code too. |
156 | 156 | |
157 | 157 | =end original |
158 | 158 | |
159 | 159 | あなたのローカルデータフォーマットに興味がある人はいないので、それは |
160 | 160 | 無視しましょう。 |
161 | 161 | ただ、その中間データはどうしましょう? |
162 | 162 | Perl 変数からツリー構造を作って、それをトラバースするのはよくあることで、 |
163 | 163 | もしそういったモジュールを誰も書いてないのであれば、そのコードも |
164 | 164 | またモジュール化したくなるでしょう。 |
165 | 165 | |
166 | 166 | =begin original |
167 | 167 | |
168 | 168 | So hopefully you've now got a few ideas about what's good to modularise. |
169 | 169 | Let's now see how it's done. |
170 | 170 | |
171 | 171 | =end original |
172 | 172 | |
173 | 173 | さあ、どんなものをモジュール化すればいいのか、だんだんわかってきたでしょう。 |
174 | 174 | これからそれをどうやってやるのか見てみましょう。 |
175 | 175 | |
176 | 176 | =head2 Step-by-step: Preparing the ground |
177 | 177 | |
178 | 178 | (Step-by-step: 地ならし) |
179 | 179 | |
180 | 180 | =begin original |
181 | 181 | |
182 | 182 | Before we even start scraping out the code, there are a few things we'll |
183 | 183 | want to do in advance. |
184 | 184 | |
185 | 185 | =end original |
186 | 186 | |
187 | 187 | コードを書きはじめる前に、やっておきたいことがいくつかあります。 |
188 | 188 | |
189 | 189 | =over 3 |
190 | 190 | |
191 | 191 | =item Look around |
192 | 192 | |
193 | 193 | (見てまわる) |
194 | 194 | |
195 | 195 | =begin original |
196 | 196 | |
197 | 197 | Dig into a bunch of modules to see how they're written. I'd suggest |
198 | 198 | starting with L<Text::Tabs|Text::Tabs>, since it's in the standard |
199 | 199 | library and is nice and simple, and then looking at something a little |
200 | 200 | more complex like L<File::Copy|File::Copy>. For object oriented |
201 | 201 | code, C<WWW::Mechanize> or the C<Email::*> modules provide some good |
202 | 202 | examples. |
203 | 203 | |
204 | 204 | =end original |
205 | 205 | |
206 | 206 | たくさんのモジュールを見て、どんな風に書かれているかみてみましょう。 |
207 | 207 | L<Text::Tabs> は標準ライブラリで、きれいに書かれていてとても |
208 | 208 | シンプルですので、これから始めると良いでしょう; それから |
209 | 209 | L<File::Copy|File::Copy> のようなもう少し複雑なものを見てください。 |
210 | 210 | オブジェクト指向のコードを書こうと思っているなら、 |
211 | 211 | C<WWW::Mechanize> や C<Mail::*> モジュールがよい例となります。 |
212 | 212 | |
213 | 213 | =begin original |
214 | 214 | |
215 | 215 | These should give you an overall feel for how modules are laid out and |
216 | 216 | written. |
217 | 217 | |
218 | 218 | =end original |
219 | 219 | |
220 | 220 | そうすれば、モジュールがどのようにレイアウトされ、書かれているか、大体 |
221 | 221 | わかってくるはずです。 |
222 | 222 | |
223 | 223 | =item Check it's new |
224 | 224 | |
225 | 225 | (新しいものかどうかチェックする) |
226 | 226 | |
227 | 227 | =begin original |
228 | 228 | |
229 | 229 | There are a lot of modules on CPAN, and it's easy to miss one that's |
230 | 230 | similar to what you're planning on contributing. Have a good plough |
231 | 231 | through the L<http://search.cpan.org> and make sure you're not the one |
232 | 232 | reinventing the wheel! |
233 | 233 | |
234 | 234 | =end original |
235 | 235 | |
236 | 236 | CPAN にはたくさんのモジュールがありますから、あなたが寄与しようとしている |
237 | 237 | モジュールとそっくりなものがあっても、見過ごしてしまうかも知れません。 |
238 | 238 | L<http://search.cpan.org> をよく見て、 |
239 | 239 | 車輪の再発明をしていないかどうか確認しましょう! |
240 | 240 | |
241 | 241 | =item Discuss the need |
242 | 242 | |
243 | 243 | (必要性を議論する) |
244 | 244 | |
245 | 245 | =begin original |
246 | 246 | |
247 | 247 | You might love it. You might feel that everyone else needs it. But there |
248 | 248 | might not actually be any real demand for it out there. If you're unsure |
249 | 249 | about the demand your module will have, consider sending out feelers |
250 | 250 | on the C<comp.lang.perl.modules> newsgroup, or as a last resort, ask the |
251 | 251 | modules list at C<modules@perl.org>. Remember that this is a closed list |
252 | 252 | with a very long turn-around time - be prepared to wait a good while for |
253 | 253 | a response from them. |
254 | 254 | |
255 | 255 | =end original |
256 | 256 | |
257 | 257 | あなたはそれを気に入っているでしょう。 |
258 | 258 | 他のみんなも、それを必要とすると思っているでしょう。 |
259 | 259 | でも、実際にはそんなに需要はないかもしれません。 |
260 | 260 | 自分のモジュールがどの程度需要があるのか不安だったら、 |
261 | 261 | C<comp.lang.perl.modules> に投稿してみましょう; それでもだめなら、 |
262 | 262 | C<modules@perl.org> のモジュールメーリングリストに聞いてみましょう。 |
263 | 263 | このメーリングリストはクローズドで、待ち時間が長いことに |
264 | 264 | 気を付けてください - レスポンスが返ってくるまでには、しばらく待つ必要が |
265 | 265 | あるかもしれません。 |
266 | 266 | |
267 | 267 | =item Choose a name |
268 | 268 | |
269 | 269 | (名前を決める) |
270 | 270 | |
271 | 271 | =begin original |
272 | 272 | |
273 | 273 | Perl modules included on CPAN have a naming hierarchy you should try to |
274 | 274 | fit in with. See L<perlmodlib> for more details on how this works, and |
275 | 275 | browse around CPAN and the modules list to get a feel of it. At the very |
276 | 276 | least, remember this: modules should be title capitalised, (This::Thing) |
277 | 277 | fit in with a category, and explain their purpose succinctly. |
278 | 278 | |
279 | 279 | =end original |
280 | 280 | |
281 | 281 | CPAN に含まれる Perl モジュールには、命名階層があり、それに合わせる |
282 | 282 | 必要があります。 |
283 | 283 | これがどのように整理されているかの詳細は、L<perlmodlib> を参照してください; |
284 | 284 | また、CPAN やモジュールリストを見て回って、どんなものか触れてみてください。 |
285 | 285 | 少なくとも、これだけは覚えておいてください: モジュール名は大文字で |
286 | 286 | 始める (This::That のように)、 カテゴリに適合している、そして、 |
287 | 287 | 目的を簡潔に説明している。 |
288 | 288 | |
289 | 289 | =item Check again |
290 | 290 | |
291 | 291 | (もう一度チェック) |
292 | 292 | |
293 | 293 | =begin original |
294 | 294 | |
295 | 295 | While you're doing that, make really sure you haven't missed a module |
296 | 296 | similar to the one you're about to write. |
297 | 297 | |
298 | 298 | =end original |
299 | 299 | |
300 | 300 | そうしている間に、書こうとしているモジュールに似たモジュールを本当に |
301 | 301 | 見過ごしていないか、確認してください。 |
302 | 302 | |
303 | 303 | =begin original |
304 | 304 | |
305 | 305 | When you've got your name sorted out and you're sure that your module is |
306 | 306 | wanted and not currently available, it's time to start coding. |
307 | 307 | |
308 | 308 | =end original |
309 | 309 | |
310 | 310 | 整理が付いて、そのモジュールは必要とされていて、まだ存在しないと |
311 | 311 | 確信したら、コードを書きはじめましょう。 |
312 | 312 | |
313 | 313 | =back |
314 | 314 | |
315 | 315 | =head2 Step-by-step: Making the module |
316 | 316 | |
317 | 317 | (Step-by-step: モジュールを作る) |
318 | 318 | |
319 | 319 | =over 3 |
320 | 320 | |
321 | 321 | =item Start with F<module-starter> or F<h2xs> |
322 | 322 | |
323 | 323 | (F<module-starter> か F<h2xs> からはじめる) |
324 | 324 | |
325 | 325 | =begin original |
326 | 326 | |
327 | 327 | The F<module-starter> utility is distributed as part of the |
328 | 328 | L<Module::Starter|Module::Starter> CPAN package. It creates a directory |
329 | 329 | with stubs of all the necessary files to start a new module, according |
330 | 330 | to recent "best practice" for module development, and is invoked from |
331 | 331 | the command line, thus: |
332 | 332 | |
333 | 333 | =end original |
334 | 334 | |
335 | 335 | F<module-starter> ユーティリティは L<Module::Starter|Module::Starter> CPAN |
336 | 336 | パッケージの一部として配布されています。 |
337 | 337 | 最近のモジュール開発の「ベストプラクティス」に基づいた、新しいモジュールを |
338 | 338 | 開始するために必要な全てのファイルの雛形を含むディレクトリを作ります; |
339 | 339 | これはコマンドラインから起動されるので: |
340 | 340 | |
341 | 341 | module-starter --module=Foo::Bar \ |
342 | 342 | --author="Your Name" --email=yourname@cpan.org |
343 | 343 | |
344 | 344 | =begin original |
345 | 345 | |
346 | 346 | If you do not wish to install the L<Module::Starter|Module::Starter> |
347 | 347 | package from CPAN, F<h2xs> is an older tool, originally intended for the |
348 | 348 | development of XS modules, which comes packaged with the Perl |
349 | 349 | distribution. |
350 | 350 | |
351 | 351 | =end original |
352 | 352 | |
353 | 353 | L<Module::Starter|Module::Starter> パッケージを CPAN から |
354 | 354 | インストールしたくない場合は、F<h2xs> はより古いツールで、本来は |
355 | 355 | XS モジュールの開発のためのもので、Perl に同梱されています。 |
356 | 356 | |
357 | 357 | =begin original |
358 | 358 | |
359 | 359 | A typical invocation of L<h2xs|h2xs> for a pure Perl module is: |
360 | 360 | |
361 | 361 | =end original |
362 | 362 | |
363 | 363 | ピュア Perl のための L<h2xs|h2xs> の典型的な起動方法は: |
364 | 364 | |
365 | 365 | h2xs -AX --skip-exporter --use-new-tests -n Foo::Bar |
366 | 366 | |
367 | 367 | =begin original |
368 | 368 | |
369 | 369 | The C<-A> omits the Autoloader code, C<-X> omits XS elements, |
370 | 370 | C<--skip-exporter> omits the Exporter code, C<--use-new-tests> sets up a |
371 | 371 | modern testing environment, and C<-n> specifies the name of the module. |
372 | 372 | |
373 | 373 | =end original |
374 | 374 | |
375 | 375 | C<-A> は Autoloader を省略し、C<-X> は XS を省略し、 |
376 | 376 | C<--skip-exporter> は Exporter コードを省略し、C<--use-new-tests> は |
377 | 377 | 近代的なテスト環境を設定し、C<-n> はモジュールの名前を指定します。 |
378 | 378 | |
379 | 379 | =item Use L<strict|strict> and L<warnings|warnings> |
380 | 380 | |
381 | 381 | (L<strict|strict> と L<warnings|warnings> を使う) |
382 | 382 | |
383 | 383 | =begin original |
384 | 384 | |
385 | 385 | A module's code has to be warning and strict-clean, since you can't |
386 | 386 | guarantee the conditions that it'll be used under. Besides, you wouldn't |
387 | 387 | want to distribute code that wasn't warning or strict-clean anyway, |
388 | 388 | right? |
389 | 389 | |
390 | 390 | =end original |
391 | 391 | |
392 | 392 | モジュールのコードは warning と strict クリーンでなくてはなりません; |
393 | 393 | どんな状況でそのモジュールが利用されるかわかりませんから。 |
394 | 394 | それに、warning や strict クリーンでないコードなんて、 |
395 | 395 | 配布したくないでしょう? |
396 | 396 | |
397 | 397 | =item Use L<Carp|Carp> |
398 | 398 | |
399 | 399 | (L<Carp|Carp> を使う) |
400 | 400 | |
401 | 401 | =begin original |
402 | 402 | |
403 | 403 | The L<Carp|Carp> module allows you to present your error messages from |
404 | 404 | the caller's perspective; this gives you a way to signal a problem with |
405 | 405 | the caller and not your module. For instance, if you say this: |
406 | 406 | |
407 | 407 | =end original |
408 | 408 | |
409 | 409 | L<Carp> モジュールを使うと、エラーメッセージを呼び出し側の視点から |
410 | 410 | 出力することが出来ます: そのモジュールではなく、呼び出し側の問題であることを |
411 | 411 | 示せるのです。 |
412 | 412 | 例えば、このようにすると: |
413 | 413 | |
414 | 414 | warn "No hostname given"; |
415 | 415 | |
416 | 416 | =begin original |
417 | 417 | |
418 | 418 | the user will see something like this: |
419 | 419 | |
420 | 420 | =end original |
421 | 421 | |
422 | 422 | ユーザはこのようなメッセージを見ることになります: |
423 | 423 | |
424 | 424 | No hostname given at /usr/local/lib/perl5/site_perl/5.6.0/Net/Acme.pm |
425 | 425 | line 123. |
426 | 426 | |
427 | 427 | =begin original |
428 | 428 | |
429 | 429 | which looks like your module is doing something wrong. Instead, you want |
430 | 430 | to put the blame on the user, and say this: |
431 | 431 | |
432 | 432 | =end original |
433 | 433 | |
434 | 434 | これでは、あなたのモジュールが何か間違ったことをしているように見えます。 |
435 | 435 | 代わりに、ユーザに責任をなすりつけられるのです; このように出力します: |
436 | 436 | |
437 | 437 | No hostname given at bad_code, line 10. |
438 | 438 | |
439 | 439 | =begin original |
440 | 440 | |
441 | 441 | You do this by using L<Carp|Carp> and replacing your C<warn>s with |
442 | 442 | C<carp>s. If you need to C<die>, say C<croak> instead. However, keep |
443 | 443 | C<warn> and C<die> in place for your sanity checks - where it really is |
444 | 444 | your module at fault. |
445 | 445 | |
446 | 446 | =end original |
447 | 447 | |
448 | 448 | こうするには、L<Carp> をつかって、C<warn> を C<carp> に置き換えます。 |
449 | 449 | もし C<die> する必要があるなら、C<croak> を使いましょう。 |
450 | 450 | ただ、本当にあなたのモジュールの責任によるチェックの場合は、 |
451 | 451 | C<warn> や C<die> のままにしておきましょう。 |
452 | 452 | |
453 | 453 | =item Use L<Exporter|Exporter> - wisely! |
454 | 454 | |
455 | 455 | (L<Exporter|Exporter> を使う - 賢く!) |
456 | 456 | |
457 | 457 | =begin original |
458 | 458 | |
459 | 459 | L<Exporter|Exporter> gives you a standard way of exporting symbols and |
460 | 460 | subroutines from your module into the caller's namespace. For instance, |
461 | 461 | saying C<use Net::Acme qw(&frob)> would import the C<frob> subroutine. |
462 | 462 | |
463 | 463 | =end original |
464 | 464 | |
465 | 465 | L<Exporter|Exporter> は、シンボルやサブルーチンをモジュールから |
466 | 466 | 呼び出し側の名前空間にエクスポートする標準的な方法がわかるでしょう。 |
467 | 467 | たとえば、C<use Net::Acme qw(&frob)> と書けば、C<frob> サブルーチンを |
468 | 468 | インポートします。 |
469 | 469 | |
470 | 470 | =begin original |
471 | 471 | |
472 | 472 | The package variable C<@EXPORT> will determine which symbols will get |
473 | 473 | exported when the caller simply says C<use Net::Acme> - you will hardly |
474 | 474 | ever want to put anything in there. C<@EXPORT_OK>, on the other hand, |
475 | 475 | specifies which symbols you're willing to export. If you do want to |
476 | 476 | export a bunch of symbols, use the C<%EXPORT_TAGS> and define a standard |
477 | 477 | export set - look at L<Exporter> for more details. |
478 | 478 | |
479 | 479 | =end original |
480 | 480 | |
481 | 481 | パッケージ変数の C<@EXPORT> によって、呼び出し側が単純に |
482 | 482 | C<use Net::Acme> と書いたときに、どのシンボルがエクスポートされるかが |
483 | 483 | 決まります - ほとんどの場合は、ここには何もいれないでしょう。 |
484 | 484 | 一方、C<@EXPORT_OK> をつかうと、どの変数をエクスポートしてもよいかを |
485 | 485 | 指定できます。 |
486 | 486 | たくさんのシンボルをエクスポートしたい場合は、C<%EXPORT_TAGS> を |
487 | 487 | 使って、エクスポートのセットを定義しましょう - 詳しくは L<Exporter> を |
488 | 488 | 参照してください。 |
489 | 489 | |
490 | 490 | =item Use L<plain old documentation|perlpod> |
491 | 491 | |
492 | 492 | (L<plain old documentation|perlpod> を使う) |
493 | 493 | |
494 | 494 | =begin original |
495 | 495 | |
496 | 496 | The work isn't over until the paperwork is done, and you're going to |
497 | 497 | need to put in some time writing some documentation for your module. |
498 | 498 | C<module-starter> or C<h2xs> will provide a stub for you to fill in; if |
499 | 499 | you're not sure about the format, look at L<perlpod> for an |
500 | 500 | introduction. Provide a good synopsis of how your module is used in |
501 | 501 | code, a description, and then notes on the syntax and function of the |
502 | 502 | individual subroutines or methods. Use Perl comments for developer notes |
503 | 503 | and POD for end-user notes. |
504 | 504 | |
505 | 505 | =end original |
506 | 506 | |
507 | 507 | 仕事はペーパーワークがすむまでは、終わりではありません; |
508 | 508 | モジュールのドキュメントを書くための時間が必要です。 |
509 | 509 | C<module-starter> か C<h2xs> を利用すれば、テンプレートを作ってくれますので、 |
510 | 510 | それを埋めればよいです; フォーマットがよくわからなければ、まずは |
511 | 511 | L<perlpod> を見てください。 |
512 | 512 | モジュールをどのように使うかのおおまかな概要、そして文法の説明や、 |
513 | 513 | それぞれのサブルーチンやメソッドの機能説明を提供してください。 |
514 | 514 | 開発者のノートとして Perl のコメントを利用し、エンドユーザへの |
515 | 515 | ノートには POD を使ってください。 |
516 | 516 | |
517 | 517 | =item Write tests |
518 | 518 | |
519 | 519 | (テストを書く) |
520 | 520 | |
521 | 521 | =begin original |
522 | 522 | |
523 | 523 | You're encouraged to create self-tests for your module to ensure it's |
524 | 524 | working as intended on the myriad platforms Perl supports; if you upload |
525 | 525 | your module to CPAN, a host of testers will build your module and send |
526 | 526 | you the results of the tests. Again, C<module-starter> and C<h2xs> |
527 | 527 | provide a test framework which you can extend - you should do something |
528 | 528 | more than just checking your module will compile. |
529 | 529 | L<Test::Simple|Test::Simple> and L<Test::More|Test::More> are good |
530 | 530 | places to start when writing a test suite. |
531 | 531 | |
532 | 532 | =end original |
533 | 533 | |
534 | 534 | ぜひユニットテストコードを作って、あなたのモジュールが、いろんな |
535 | 535 | プラットフォーム上の Perl で、意図した通りにうまく動くことを確認しましょう; |
536 | 536 | CPAN にモジュールをアップロードすると、たくさんのテスターがモジュールを |
537 | 537 | ビルドして、テストの結果をあなたに送ってくれるでしょう。 |
538 | 538 | ここでもまた、C<module-starter> と C<h2xs> を使えば、後で拡張可能な、 |
539 | 539 | テストフレームワークが提供されます - 単にコンパイルが通るかだけでなく、 |
540 | 540 | いろいろとテストしましょう。 |
541 | 541 | L<Test::Simple|Test::Simple> と L<Test::More|Test::More> は、テスト |
542 | 542 | スイートを書くときの開始点としてよいものです。 |
543 | 543 | |
544 | 544 | =item Write the README |
545 | 545 | |
546 | 546 | (README を書く) |
547 | 547 | |
548 | 548 | =begin original |
549 | 549 | |
550 | 550 | If you're uploading to CPAN, the automated gremlins will extract the |
551 | 551 | README file and place that in your CPAN directory. It'll also appear in |
552 | 552 | the main F<by-module> and F<by-category> directories if you make it onto |
553 | 553 | the modules list. It's a good idea to put here what the module actually |
554 | 554 | does in detail, and the user-visible changes since the last release. |
555 | 555 | |
556 | 556 | =end original |
557 | 557 | |
558 | 558 | CPAN にアップロードするときは、README ファイルが自動で抽出されて、 |
559 | 559 | あなたの CPAN ディレクトリに置かれます。 |
560 | 560 | また、モジュールリストに載った場合には、F<by-module> や F<by-category> の |
561 | 561 | メインディレクトリにも配置されます。 |
562 | 562 | このファイルに、そのモジュールのすることの詳細や、一つ前のリリースからの |
563 | 563 | 変更点を書いておくと良いでしょう。 |
564 | 564 | |
565 | 565 | =back |
566 | 566 | |
567 | 567 | =head2 Step-by-step: Distributing your module |
568 | 568 | |
569 | 569 | (Step-by-step: モジュールを配布する) |
570 | 570 | |
571 | 571 | =over 3 |
572 | 572 | |
573 | 573 | =item Get a CPAN user ID |
574 | 574 | |
575 | 575 | (CPAN ユーザ ID を取得する) |
576 | 576 | |
577 | 577 | =begin original |
578 | 578 | |
579 | 579 | Every developer publishing modules on CPAN needs a CPAN ID. Visit |
580 | 580 | C<http://pause.perl.org/>, select "Request PAUSE Account", and wait for |
581 | 581 | your request to be approved by the PAUSE administrators. |
582 | 582 | |
583 | 583 | =end original |
584 | 584 | |
585 | 585 | CPAN でモジュールを配布するには、CPAN ID が必要です。 |
586 | 586 | C<http://pause.perl.org/> に訪れて、"Request PAUSE Account" を選択し、 |
587 | 587 | リクエストが PAUSE 管理者に承認されるのを待ちましょう。 |
588 | 588 | |
589 | 589 | =item C<perl Makefile.PL; make test; make dist> |
590 | 590 | |
591 | 591 | =begin original |
592 | 592 | |
593 | 593 | Once again, C<module-starter> or C<h2xs> has done all the work for you. |
594 | 594 | They produce the standard C<Makefile.PL> you see when you download and |
595 | 595 | install modules, and this produces a Makefile with a C<dist> target. |
596 | 596 | |
597 | 597 | =end original |
598 | 598 | |
599 | 599 | ここでも、C<module-starter> や C<h2xs> はすべてやってくれます。 |
600 | 600 | モジュールをインストールするときによく見る、標準的な C<Makefile.PL> が |
601 | 601 | できています; これが生成する Makefile に C<dist> ターゲットがあります。 |
602 | 602 | |
603 | 603 | =begin original |
604 | 604 | |
605 | 605 | Once you've ensured that your module passes its own tests - always a |
606 | 606 | good thing to make sure - you can C<make dist>, and the Makefile will |
607 | 607 | hopefully produce you a nice tarball of your module, ready for upload. |
608 | 608 | |
609 | 609 | =end original |
610 | 610 | |
611 | 611 | モジュールがテストにパスしたことを確認したら(いつでも確認することは |
612 | 612 | よいことです)、C<make dist> を実行すれば、Makefile はアップロード準備の |
613 | 613 | 整った tarball ファイルを生成してくれます。 |
614 | 614 | |
615 | 615 | =item Upload the tarball |
616 | 616 | |
617 | 617 | (tarball をアップロードする) |
618 | 618 | |
619 | 619 | =begin original |
620 | 620 | |
621 | 621 | The email you got when you received your CPAN ID will tell you how to |
622 | 622 | log in to PAUSE, the Perl Authors Upload SErver. From the menus there, |
623 | 623 | you can upload your module to CPAN. |
624 | 624 | |
625 | 625 | =end original |
626 | 626 | |
627 | 627 | CPAN ID を取得できたときに届く email に、PAUSE (the Perl Authors |
628 | 628 | Upload SErver) へのログイン方法が載っています。 |
629 | 629 | メニューから選択して、モジュールをCPANにアップロードできます。 |
630 | 630 | |
631 | 631 | =item Announce to the modules list |
632 | 632 | |
633 | 633 | (モジュールリストにアナウンスする) |
634 | 634 | |
635 | 635 | =begin original |
636 | 636 | |
637 | 637 | Once uploaded, it'll sit unnoticed in your author directory. If you want |
638 | 638 | it connected to the rest of the CPAN, you'll need to go to "Register |
639 | 639 | Namespace" on PAUSE. Once registered, your module will appear in the |
640 | 640 | by-module and by-category listings on CPAN. |
641 | 641 | |
642 | 642 | =end original |
643 | 643 | |
644 | 644 | アップロードしたら、あなたのディレクトリにあるだけでは人目を引きません。 |
645 | 645 | 他のの CPAN モジュールと同じように載せたければ、PAUSE の |
646 | 646 | "Register Namespace" に行く必要があります。 |
647 | 647 | 登録されると、あなたのモジュールは CPAN のモジュール別およびカテゴリ別の |
648 | 648 | リストに表示されます。 |
649 | 649 | |
650 | 650 | =item Announce to clpa |
651 | 651 | |
652 | 652 | (clpa にアナウンスする) |
653 | 653 | |
654 | 654 | =begin original |
655 | 655 | |
656 | 656 | If you have a burning desire to tell the world about your release, post |
657 | 657 | an announcement to the moderated C<comp.lang.perl.announce> newsgroup. |
658 | 658 | |
659 | 659 | =end original |
660 | 660 | |
661 | 661 | リリースしたことを世界中にアナウンスしたいという野望があるなら、 |
662 | 662 | モデレートされている、C<comp.lang.perl.announce> ニュースグループに |
663 | 663 | アナウンスを投稿してみましょう。 |
664 | 664 | |
665 | 665 | =item Fix bugs! |
666 | 666 | |
667 | 667 | (バグをなおす!) |
668 | 668 | |
669 | 669 | =begin original |
670 | 670 | |
671 | 671 | Once you start accumulating users, they'll send you bug reports. If |
672 | 672 | you're lucky, they'll even send you patches. Welcome to the joys of |
673 | 673 | maintaining a software project... |
674 | 674 | |
675 | 675 | =end original |
676 | 676 | |
677 | 677 | ユーザが集まってくると、バグレポートが送られて来ます。 |
678 | 678 | 運がよければ、パッチを送ってくれるでしょう。 |
679 | 679 | ソフトウェアプロジェクトのメンテナンスという喜びが待っています ... |
680 | 680 | |
681 | 681 | =back |
682 | 682 | |
683 | 683 | =head1 AUTHOR |
684 | 684 | |
685 | 685 | Simon Cozens, C<simon@cpan.org> |
686 | 686 | |
687 | 687 | Updated by Kirrily "Skud" Robert, C<skud@cpan.org> |
688 | 688 | |
689 | 689 | =head1 SEE ALSO |
690 | 690 | |
691 | 691 | =begin original |
692 | 692 | |
693 | 693 | L<perlmod>, L<perlmodlib>, L<perlmodinstall>, L<h2xs>, L<strict>, |
694 | 694 | L<Carp>, L<Exporter>, L<perlpod>, L<Test::Simple>, L<Test::More> |
695 | 695 | L<ExtUtils::MakeMaker>, L<Module::Build>, L<Module::Starter> |
696 | 696 | http://www.cpan.org/ , Ken Williams's tutorial on building your own |
697 | 697 | module at http://mathforum.org/~ken/perl_modules.html |
698 | 698 | |
699 | 699 | =end original |
700 | 700 | |
701 | 701 | L<perlmod>, L<perlmodlib>, L<perlmodinstall>, L<h2xs>, L<strict>, |
702 | 702 | L<Carp>, L<Exporter>, L<perlpod>, L<Test::Simple>, L<Test::More> |
703 | 703 | L<ExtUtils::MakeMaker>, L<Module::Build>, L<Module::Starter> |
704 | 704 | http://www.cpan.org/ , http://mathforum.org/~ken/perl_modules.html にある、 |
705 | 705 | Ken Williams による自作のモジュールをビルドするためのチュートリアル。 |
706 | 706 | |
707 | 707 | =begin meta |
708 | 708 | |
709 | 709 | Translate: miyagawa |
710 | 710 | Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.0-) |
711 | 711 | Status: completed |
712 | 712 | |
713 | 713 | =end meta |