DRYではない気がするけど、実行するスクリプトやモジュールにいちいち、
BEGIN {
if ($ENV{SMART_COMMENTS}) {
use UNIVERSAL::require;
Smart::Comments->use;
}
}もしくは
BEGIN {
if ($ENV{SMART_COMMENTS}) {
my @p = map { '#'x$_ } ($ENV{SMART_COMMENTS} =~ /([345])\s*/g);
use UNIVERSAL::require;
Smart::Comments->use(@p);
}
}と書いておくのはどうだろう?
後者だと、デバッグメッセージ表示したいときは
$ env SMART_COMMENTS=t hoge.pl
とか
$ env SMART_COMMENTS='4 5' hoge.pl
とかすればおk。
むぅ。
package P;
use strict;
use warnings;
sub enable {
return <<'END_ENABLE';
my $debug_flag = $ENV{SMART_COMMENTS} || $ENV{SMART_COMMENT} || $ENV{SMART_DEBUG} || $ENV{SC};
if ($debug_flag) {
my @p = map { '#'x$_ } ($debug_flag =~ /([345])\s*/g);
use UNIVERSAL::require;
Smart::Comments->use(@p);
}
END_ENABLE
}
1;
__END__で、
use UNIVERSAL::require;
BEGIN { P->use && eval &P::enable; }の方がちびっとましか?