Text::Xslate::Syntax::Kolonについてメモ
今日覚えたこととか。
実はKolonとはあんまり関係ないかもしれない。
#!perl use strict; use warnings; use Encode; use Text::Xslate; use Data::Section::Simple; my $vpath = Data::Section::Simple->new()->get_data_section(); my $tx = Text::Xslate->new( path => [ $vpath ] ); my $html = $tx->render('index.tx'); print encode('cp932', $html); __DATA__ @@ index.tx : #-------------------------------------------------- : # constant : #-------------------------------------------------- : my $hoge = '師走' <: "そろそろ$hoge" # 「そろそろ$hoge」と出力 :> <: "そろそろ"~$hoge # 「そろそろ師走」 と出力 :> : #-------------------------------------------------- : # map : #-------------------------------------------------- : my $array = [1,2,3].map(-> $a { $a * 10 } ) : for $array -> $item { <: $item :> : } : #-------------------------------------------------- : # macro : #-------------------------------------------------- : include 'macro.tx' : # good_morning('john') # ダメ @@ macro.tx : macro good_morning -> $name { Good morning <: $name :> : }
map
「-> $a」で宣言されてるのが配列の各要素を表す変数で後ろに続くブロックが各要素にしたい処理、だと思う。イマイチこの辺の書き方に自信が持てない。「Anonymous macro」と一緒にも見えるなあ。
macro
別ファイルにマクロを一杯書いてそれをincludeして使うみたいのは出来ないようである。
ちょっとしたことで一々perldocしなくてもいけるようになって最近はいい感じである。