BlockCondTest01
構成
$MT_DIR/
|__ plugins/
| |__ BlockCondTest01/
| |__ config.yaml
| |__ lib/
| | |__ BlockCondTest01
| |__ Tag.pm
ソース
config.yaml
# 基本パラメータ
id: BlockCondTest01
key: BlockCondTest01
name: BlockCondTest01
# タグ定義
tags:
# ブロックタグ
block:
# コンディショナルタグ
BlockCondTest01If?: $BlockCondTest01::BlockCondTest01::Tag::_hdlr_block_cond
# ブロックタグ
BlockCondTest01: $BlockCondTest01::BlockCondTest01::Tag::_hdlr_block
# ファンクションタグ
function:
BlockCondFunc01: $BlockCondTest01::BlockCondTest01::Tag::_hdlr_function
lib/BlockCondTest01/Tag.pm
package BlockCondTest01::Tag;
use strict;
# BlockCondTest01の処理
sub _hdlr_block_cond{
# 引数を取得
my ($ctx, $args, $cond) = @_;
my $count = $ctx->stash('myplugin::count');
# $count変数が取得できていない場合はエラー
return $ctx->error ('BlockCondTest01 must be used in BlockCondTest01Loop') if !defined $count;
my $res;
if($count % 2 == 1){
$res = 1;
}else{
$res = 0;
}
# 返却
return $res;
}
# BlockCondTest01の処理
sub _hdlr_block{
# 引数を取得
my ($ctx, $args, $cond) = @_;
# コンテキストよりbuilderを取得
my $builder = $ctx->stash('builder');
# トークンを取得
my $tokens = $ctx->stash('tokens');
# count="xxx"の引数を取得、存在しない場合は"1"
my $loop = $args->{count} || 1;
# 初期化
my $html = '';
for (my $count = 1; $count <= $loop; $count++) {
# ローカルスコープへ値を一時的に設定
local $ctx->{__stash}{'myplugin::count'} = $count;
# ブロックタグを構築、失敗時はエラー
my $out = $builder->build ($ctx, $tokens, $cond);
return $ctx->error ($builder->errstr) if !defined $out;
# 値連結
$html .= $out;
}
# 値返却
return $html;
}
# BlockCondFunc01の処理
sub _hdlr_function{
# 引数を取得
my ($ctx, $args) = @_;
my $count = $ctx->stash('myplugin::count');
# $count変数が取得できていない場合はエラー
return $ctx->error ('BlockCondTest01 must be used in BlockCondTest01Loop') if !defined $count;
# 取得した$count変数を返却
return $count;
}
1;
最終更新:2012年03月08日 22:37