BlockTest03

構成

$MT_DIR/
|__ plugins/
|  |__ BlockTest03/
|     |__ config.yaml
|     |__ lib/                    
|     |  |__ BlockTest03
|            |__ Plugin.pm
 
 
 

ソース

config.yaml

id: block03
key: BlockTest03
name: BlockTest03
tags:
    block:
        BlockTest03: $BlockTest03::BlockTest03::Plugin::hdlr_func03
    function:
        FunctionTest03: $BlockTest03::BlockTest03::Plugin::hdlr_func03a
 
 

lib/BlockTest03/Plugin.pm

package BlockTest03::Plugin;
 
use strict;
 
sub hdlr_func03{
 
    # 引数を取得
    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;
}
 
sub hdlr_func03a{
 
    # 引数を取得
    my ($ctx, $args) = @_;
 
    my $count = $ctx->stash('myplugin::count');
 
    # $count変数が取得できていない場合はエラー
    return $ctx->error ('MTMyLoopCount must be used in MTMyLoop') if !defined $count;
 
    # 取得した$count変数を返却
    return $count;
 
}
 
1;
 
 



最終更新:2012年01月25日 01:11