Fork me on GitHub

2008/10/10

Recent entries from same category

  1. すぎゃーんさんの「Amon2::Liteでmarkdownその他のリアルタイムプレビュー」をfluxflexで動かしてみた。 Hatena
  2. Amon2でGyazo作ってdotcloudにpushしてみた。 Hatena
  3. 今すぐフォローすべきPerl界のスーパーエンジニアをPerlでフォローする、たった一つかもしれない方法 Hatena
  4. CPANモジュールガイドを献本頂きました。 Hatena
  5. 画像の直リンをウンコ画像に差し替えるPlack::Middleware書いた。 Hatena

このエントリーをはてなブックマークに追加
今のところ使い道見つからないけど、面白い。
Chris Grau / Export-Lexical - search.cpan.org

Export::Lexical - Lexically scoped subroutine imports

http://search.cpan.org/dist/Export-Lexical/
SYNOPSISをちょと変えて
use strict;
use warnings;
package Foo;

use Export::Lexical;
sub foo :ExportLexical {
    print "foo@_\n" or 1;
}
sub bar :ExportLexical {
    print "bar@_\n" or 1;
}
1;
を使う以下のスクリプト
use strict;
use warnings;
use Foo;

no Foo 'foo';

eval { foo(1); } or warn "foo1 is disabled.";
eval { bar(1); } or warn "bar1 is disabled.";

{
    use Foo 'foo';
    no Foo 'bar';

    eval { foo(2); } or warn "foo2 is disabled.";
    eval { bar(2); } or warn "bar2 is disabled.";
}

eval { foo(3); } or warn "foo3 is disabled.";
eval { bar(3); } or warn "bar3 is disabled.";
実行すると
foo1 is disabled. at hoge.pl line 7.
bar1
foo2
bar2 is disabled. at hoge.pl line 15.
foo3 is disabled. at hoge.pl line 18.
bar3
こんな動きをする。レキシカルスコープでnoが使える。ただnoとは言えどメソッド自体は定義されてるからstrictでも通るし、eval無しで実行してもエラーにはならない。

面白い。でも使い道が見つからない。
Posted at 12:14 in ソフトウェア::lang::perl | Edit
Tagged as: perl
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

blog comments powered by Disqus