tokuhirom's blog.

'; DROP DATABASE database();

I need :BEGIN attribute for subroutine

最近すごく「欲しいの。。。」とおもっているのが :BEGIN 属性あるいはそれにかわるなにかだ。

Moose's 'extends' has a problem.

extends 'Foo';

'extends' is evaluated at run-time!This cause some problems.Basically solution for this problem is:

BEGIN { extends 'Foo'; }

agghhhhhhh!! F*cking interface!

I need the interface like following snippet.

package Moose;
use Exporter 'import';
sub extends :BEGIN {
  my $caller = caller(0);
  for (@_) {
    Class::MOP::load_class($_);
    unshift @{$caller.'::ISA'}, $_;
  }
}

ってなことを妄想してるんだけど、どうだろう。

「このメソッドはコンパイル時にうごいてくれよん」ということを指定してエクスポートできるメソッドというものがあると、なにかと便利だとおもう。とくに DSL を定義するときには。本来 Moose のメソッドはコンパイル時にうごくべきものなわけですし。

【追記】

02:02 Sartak: tokuhirom: Devel::BeginLift gives you what you asked for. if you really want the interface to be a function attribute, I'm sure you could write a wrapper to do it

とのこと。

【追記】
えーっと、Moose は例として出してるだけなのでどうでもいいです。「この関数はコンパイル時に評価する」という宣言があると便利じゃね?ってのが本題。