Smart::Commentsが超便利

今更だけど・・・知らなかったので。デバッグ出力用のモジュールらしいです。

Smart::Comments - Comments that do more than just sit there - metacpan.org


変数の値をData::Dumper的に*1ダンプしたり、現在時間を出したり、プログレスバーを出したりと便利な機能がたくさんあります。
Smart::Commentsを使わなければ単なるコメントとして無視されるというのも素晴らしい。
コード内で use Smart::Comments してもいいけど、コマンドラインオプションで-MSmart::Commentsすれば、ソースコードとしては完全に単なるコメントとして認識されるし、コマンドラインデバッグのON/OFFも簡単にできるという・・・まさに至れり尽くせりですね。
ただ、コマンドラインで指定するときは、実行されたソースファイル単体でのみ有効で、中で使ってるモジュールとかには適用されないらしいので注意ですね。

Of course, this only enables smart comments in the application file itself, not in any modules that the application loads.

Smart::Comments - Comments that do more than just sit there - metacpan.org

Foo.pm の中に ### ではじまる Smart Comments がある場合は、 perl -MSmart::Comments foo.pl では有効にならない。Smart::Comments はソースフィルタだから use したコンテキストでしかフィルタがきかない。

[perl] use Smart::Comments - Bulknews::Subtech - subtech

サンプル

use strict;
use warnings;

my $data = {
  a => 1,
  c => {
    d => 3,
    e => 4,
  },
  b => 2,
};

### [<now>] debug output
### $data

for(1..10){ ### loop [===  ] %
  sleep 1;
}
$ perl -MSmart::Comments sample.pl

### [Tue Oct 14 11:50:59 2008] debug output
### $data: {
###          a => 1,
###          b => 2,
###          c => {
###                 d => 3,
###                 e => 4
###               }
###        }
loop [=====                   ] 22%

こ、これは便利すぎる・・・。

*1:QuotekeysとかSortkeysの設定も適当にされてるっぽい!