Xslate now cooperates with Data::Section::Simple

[twitter:@typester]さんがText::MicroTemplate::DataSectionを書いて気になっていたところ、[twitter:@kazeburo]さんからもXslateの対応について要求があったので、version 0.1043でData::Section::Simpleと協調するようにしました。
ただし、依存モジュールを増やしたくない*1ので直接サポートではありません。
具体的には、以下のように使います*2

#!perl -w
use strict;

use Text::Xslate;
use Data::Section::Simple;

my $tx = Text::Xslate->new(
    path => [
        Data::Section::Simple
            ->new()->get_data_section(),
    ],
);

print $tx->render('child.tx');

__DATA__

@@ base.tx
<html>
<body>
<: block body -> { :>default body<: } :>
</body>
</html>
@@ child.tx
: cascade base;
: override body -> {
child body
: } # endblock body

実行結果:

<html>
<body>
child body

</body>
</html>

つまり、pathオプションにハッシュリファレンスを渡すとそれを仮想的にファイルシステムとみなしてファイルを検索します。pathオプションの拡張として実装したのは、優先度を制御できるようにするためです。
なお、通常のファイルと同じようにキャッシュも効くので、速度的なペナルティはありません。
Enjoy!

*1:「小難しいことはWAFでやれ」がコンセプトなので

*2:example/data_section.plに実行可能なスクリプトがあります。例はText::MicroTemplate::DataSectionから移植しました。